0

I just recently upgraded to Jackson 2.0.5 and discovered this new attribute called @JsonIdentityInfo that allows you do define an object once, but then have the serializer create references to that single object, without creating duplicates every time its seen. Quite nice actually. http://wiki.fasterxml.com/JacksonFeatureObjectIdentity

The documentation states that this feature does not yet currently support arrays. I was wondering if anyone knows of any other approach to this? I have a snippet of JSON that might look like this:

{
    "people":[ 
       { "@id" = 1, "name"="bill"},
       { "@id" = 2, "name"="joe"}
    ],
    "friends": [1,2]

}

I'd like to have "friends" inflate with the array of "person" objects, in the same way that "people" will. Does anyone know of a way to do this?

2 Answers 2

1

What you can do is to use a wrapper POJO that only contains array or List. That POJO can use identity-handling normally. It adds one extra level, but should work nicely.

If you would like to see support for List/array types, make sure to file a RFE at Github. While non-trivial to implement, it's possible, just quite a bit of work (which is why original implementation focused on things expressed as JSON Objects).

Sign up to request clarification or add additional context in comments.

Comments

1

you can do that with JSOG JS library: https://github.com/jsog/jsog, but you need serialize data like:

{
"people":[ 
   { "@id" = 1, "name"="bill"},
   { "@id" = 2, "name"="joe"}
],
"friends": [ {@ref = 1}, {@ref = 2}]

}

or modify JSOG Library.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.