johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Broadhead <matthew.broadh...@nbmlaw.co.uk>
Subject Re: mixed object array
Date Thu, 08 Sep 2016 11:17:43 GMT
i changed to send xml instead of jzon.  shame we can't use jaxb 
annotations anymore :(

On 08/09/2016 12:03, Romain Manni-Bucau wrote:
> Hello
>
> comments inline
> <https://javaeefactory-rmannibucau.rhcloud.com>
>
> 2016-09-08 11:56 GMT+02:00 Matthew Broadhead <matthew.broadhead@nbmlaw.co.uk
>> :
>> I am using TomEE 7.0.1 which is now defaulting to Johnzon where on 1.7.x
>> the default was jettison.  i have a specific case where i am using jaxb
>> annotations to specify a mixed object array where elements in the array can
>> be for example ObjectType1 or ObjectType2.  using jettison it worked fine
>> across jaxrs
>>
>> @XmlElements({ @XmlElement(name = "objectType1", type = ObjectType1.class),
>>                          @XmlElement(name = "objectType2", type =
>> ObjectType2.class) })
>> @XmlElementWrapper
>> public List getObjectBlocks() {
>>          return objectBlocks;
>> }
>>
>> I would be happy to use Johnzon instead of Jettison if it could provide an
>> annotation that addresses this issue however i cannot find much
>> documentation about johnzon.  or maybe johnzon has a way of supporting jaxb?
>>
> No way to support jaxb cause jsonb (JSON mapping spec) doesnt match it and
> default johnzon mapper is very close to the spec which will prevent several
> migrations when targetting EE 8.
>
> On the serialization it should work out of the box, issue is on
> deserialization side and here jaxb works cause it has wrappers and
> namespace. This is not a common practise in JSON so there is no strict
> equivalent. However one way to do that is to wrap at serialization time the
> instance in a wrapper containing the class. This is the solution on jsonb
> side (see this test for instance
> https://github.com/apache/johnzon/blob/745668a81818ec37aed31dc6db868740191a9806/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/SerializerTest.java#L65).
> Johnzon has more or less the same kind of API through ObjectConverter, see
> this other test
> https://github.com/apache/johnzon/blob/745668a81818ec37aed31dc6db868740191a9806/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/ObjectTypeTest.java#L163
>


Mime
View raw message