Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializing stdClass with arbitrary depth #414

Closed
erichjsonfosse opened this issue Sep 22, 2014 · 4 comments
Closed

Serializing stdClass with arbitrary depth #414

erichjsonfosse opened this issue Sep 22, 2014 · 4 comments

Comments

@erichjsonfosse
Copy link

When serializing objects of stdClass, I never seem to be able to go deeper than 2.

For example, an entity has a property of type stdClass, which has an array of objects of type stdClass which has both properties of type stdClass, and arrays of objects of type stdClass.

The output should be like this (stdClass object is "theStdObject"):

{
  "Id": 452,
  "Heading": "Cool heading",
  "TeaserText": "Tease tease",
  "TagLine": "Great tag line",
  "MainIntro": "lorem ipsum",
  "SomeProperty": 854,
  "TopImageUrl": "http://foo.bar/baz.png",
  "GoogleMapsLocation": {
    "Address": "Address text",
    "Latitude": 1.2,
    "Longtitude": 12.4,
    "ZoomLevel": 14
  },
  "theStdObject": {
    "anId": 35389458,
    "aName": "Test",
    "anInteger": 0,
    "anArrayOfObjects": [
      {
        "anId": 35389459,
        "aName": "Test 2",
        "ItmLevel": 1,
        "anArrayOfObjects": [
          {
            "ItmId": 18612229,
            "ItmName": "Test 3",
            "ItmLevel": 2,
            "SubProjects": [],
            "RelevantConcepts": [],
            "Address": {
              "StreetAddress": "Kornmoveien 10-22",
              "ZipCode": null,
              "County": null,
              "State": null,
              "PostalCity": null,
              "HasData": true
            },
            "PrimaryConceptId": null,
            "ParentProjectId": 35389459
          },
          {
            "ItmId": 35389461,
            "ItmName": "Test 4",
            "ItmLevel": 2,
            "PrimaryConceptId": null
          }
        ],
        "anObject": {
          "StreetAddress": null,
          "ZipCode": null,
          "County": null,
          "State": null,
          "PostalCity": null,
          "HasData": false
        }
      },
      {
        "anId": 68943884,
        "aName": "Test 5",
        "ItmLevel": 1,
        "anArrayOfObjects": [
          {
            "ItmId": 35389460,
            "ItmName": "Test 6",
            "ItmLevel": 2,
            "Address": {
              "StreetAddress": "String",
              "ZipCode": null,
              "County": "String",
              "State": "String",
              "PostalCity": "String",
              "HasData": true
            },
            "PrimaryConceptId": null,
            "ParentProjectId": 68943884
          }
        ],
        "anObject": {
          "StreetAddress": null,
          "ZipCode": null,
          "County": null,
          "State": null,
          "PostalCity": null,
          "HasData": false
        }
      }
    ],
    "anObject": {
      "StreetAddress": "text value",
      "ZipCode": null,
      "County": null,
      "State": null,
      "PostalCity": null
    }
  }
}

but instead, I get this:

{
  "Id": 452,
  "Heading": "Cool heading",
  "TeaserText": "Tease tease",
  "TagLine": "Great tag line",
  "MainIntro": "lorem ipsum",
  "SomeProperty": 854,
  "TopImageUrl": "http://foo.bar/baz.png",
  "GoogleMapsLocation": {
    "Address": "Address text",
    "Latitude": 1.2,
    "Longtitude": 12.4,
    "ZoomLevel": 14
  },
  "theStdObject": {
    "anId": 35389458,
    "aName": "Test",
    "anInteger": 0,
    "anArrayOfObjects": [
      { },
      { }
    ],
    "anObject": { }
  }
}

I understand that the max_depth property sets a limit that normaly isn't set, but I've tried setting it to a high number without any luck.

Am I doing something wrong?

@erichjsonfosse
Copy link
Author

Forgot to mention that the above is true when the yml config for the entity specifies that "theStdObject" is of type array.
When it is of type stdClass, it shows up as an empty object.

@erichjsonfosse
Copy link
Author

Also, I guess this is a duplicate of #158 and schmittjoh/serializer#211 . Closing this issue. Sorry for the repost.

@erichjsonfosse
Copy link
Author

On second thought, the commit done in schmittjoh/serializer#211 sets the data type to array, which still doesn't output objects of arbitrary depth.

Any feedback on this is greatly appreciated.

@AlexSkrypnyk
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants