users@jersey.java.net

[Jersey] Re: Question regarding json and attributes

From: John Yeary <johnyeary_at_gmail.com>
Date: Thu, 5 Jan 2012 14:08:32 -0500

Have you looked at BadgerFish for encoding your JSON objects? The
JAXBContext can be configured to use BadgerFish which handles XML
attributes and values. I think that BadgerFish uses @ symbols so you may
need to change that. It does however encode both attributes and elements
correctly.

On Thu, Jan 5, 2012 at 2:04 PM, Oded Hassidi <oded.hassidi_at_gmail.com> wrote:

> the issue is that my object (entity) defines type as an attribute and the
> state as element and when I send the request with the attribute second the
> object comes to the resource with the an empty attribute
>
> On Thu, Jan 5, 2012 at 15:30, John Yeary <johnyeary_at_gmail.com> wrote:
>
>> JSON is a name=value pair mapping, so order is not important for that.
>> Your application as noted should be fine.
>>
>> If you need to have order, you may consider wrapping the objects in a
>> GenericEntity<List<?>> to maintain some ordering. In general, the arrays
>> created in JSON are ordered from the Java side of the application. So using
>> arrays will maintain order from the server side. I can not vouch for what
>> your client side code will do.
>>
>> John
>>
>>
>> On Thu, Jan 5, 2012 at 5:04 AM, Oded Hassidi <oded.hassidi_at_gmail.com>wrote:
>>
>>> Hi all,
>>>
>>> I have Jersey and JAXB used for translating json and xml to objects.
>>> My objects define attributes and in json they go out with @ sign. In
>>> json as far as I know there is no importance to the order of the name,
>>> value pairs.
>>>
>>> The question is: if we define attribute do they break the above
>>> assumption?
>>> is this: {"event":{"state":"ended","@type":"state"}}
>>> different from this: {"event":{"@type":"state", "state":"ended"}}
>>> when jersey build the java object?
>>>
>>> Thanks
>>>
>>
>>
>>
>> --
>> John Yeary
>> --
>> http://javaevangelist.blogspot.com
>> http://www.johnyeary.com
>> *_at_jyeary*
>>
>> "Far better it is to dare mighty things, to win glorious triumphs, even
>> though checkered by failure, than to take rank with those poor spirits who
>> neither enjoy much nor suffer much, because they live in the gray twilight
>> that knows not victory nor defeat."
>> -- Theodore Roosevelt
>>
>
>


-- 
John Yeary
--
http://javaevangelist.blogspot.com
http://www.johnyeary.com
*_at_jyeary*
"Far better it is to dare mighty things, to win glorious triumphs, even
though checkered by failure, than to take rank with those poor spirits who
neither enjoy much nor suffer much, because they live in the gray twilight
that knows not victory nor defeat."
-- Theodore Roosevelt