users@jersey.java.net

Re: [Jersey] Json output not always matching xml output

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 20 Nov 2009 12:03:59 +0100

Hi,

The thing which is slightly odd is that the first score attribute is
not an array where as the second score attribute is an array:

{"release-group-list":{"offset":0,"count":2,"release-group":[{"type":
["compilation
"],"id":"765675cc-070b-36e0-829c-69c7634e92ff",*"score":"100"*,
"title":"The History of John Fred and the Playboys",
"artist-credit":{"name-credit":[{"artist":{"id":"05cfb5c7-0152-41f4-
a9c9-622e8f710dfa","name":"John Fred & His Playboy Band","sort-
name":"Fred, John & His Playboy Band"}}]},"release-list":{"count":1,
"release":[{"id":"9cddae0c-1764-41d2-a1c4-0af2a8404e57","title":"The
History of John Fred and the Playboys"}]}},
{"type":["live"],"id":"9856e177-6a63-3141-96da-00b80d08c66e",*"score":
["100"]*,


Is there an inconsistency for JSON/JAXB natural serialization for
wildcard attributes.

Paul.

On Nov 19, 2009, at 5:51 PM, Jakub Podlesak wrote:

>
> Hi Paul,
>
> please see inline...
>
> On Wed, Nov 18, 2009 at 08:12:35PM +0000, Paul Taylor wrote:
>> Jakub Podlesak wrote:
>>> Hi Paul,
>>>
>>> It turns out, JAXB runtime does not provide correct information
>>> on the score attribute in this (unfortunate xs:anyAttribute) case.
>>> I am not sure this could be fixed easily, but you can try using the
>>> following
>>> JSON configuration as a workaround:
>>>
>>> return new JSONJAXBContext(
>>> JSONConfiguration
>>> .mapped()
>>> .attributeAsElement("score")
>>> .arrays("release-group")
>>> // comment this out, if you want to get string
>>> "50"
>>> instead of number 50
>>> .nonStrings("score")
>>> .build(),
>>> "org.musicbrainz.mmd2");
>>>
>>> in the initJsonContext method.
>>>
>>> Which gives me:
>>>
>>> {"release-group-list":{"release-group":[{"score":50},{"score":50},
>>> {"score":50},{"score":50},{"score":50}]}}
>>>
>>> HTH,
>>>
>>> ~Jakub
>>>
>>
>> Hmm, Unfortunately I need to use mapping natural() so that the json
>> matches the form of json returned by another (non-java) api , and
>> this
>> doesn't have the attributesAsElement option so I can't use this
>> workaround.
>
> I do not understand. What matters is the JSON format, and the only
> thing
> you get from using attributeAsElement option in Jersey is you get
> rid of
> the '@' prefixes. The other (non-java) api should be able to process
> such JSON data. What am i missing?
>
>> I could modify the xsd though, could you show me how to change the
>> xsd
>> so that there is a score attribute on releasegroup which is (and
>> this is
>> the bit i don't get) is a part of the "http://musicbrainz.org/ns/ext#-2.0
>> "
>> namespace rather than the main namespace.
>
> O.K. i could provide you st later tonight my time.
>
>>
>> and are you saying there is a bug/omission in JAXB or just that
>> Jersey
>> depends on extra information that JAXB doesnt have , and never
>> will do
>> because its not required by JAXB.
>
> I am saying i need to update JAXB to provide such info to Jersey.
> I wrote the integration part in JAXB impl, so i just need to revisit
> that
> as you hit kind of a corner case here, and this was not covered
> initially.
> Anyway, it would need to wait for another
> stable release of JAXB impl before this could be utilized in a
> stable Jersey release.
>
>
> ~Jakub
>
>
>>
>> thanks Paul
>
> --
> Jakub Podlešák
> Software Engineer at SUN Microsystems And CZJUG Co-Leader
> http://blogs.sun.com/japod