Hi,
please look at the very end...
On Wed, Apr 01, 2009 at 11:51:56AM +0200, Paul Sandoz wrote:
>
> On Mar 31, 2009, at 3:47 PM, Kytömäki, Janne wrote:
>
>> Hi,
>>
>>>> Another question: is it possible to do the same (sub-class) with
>>>> JSON? Maybe with jettison notation?
>>
>> I'd also like to get de-serialization of JSON objects
>> with inheritance working, but haven't figured out how to do it yet,
>> at least with the default JSON notation. For example:
>>
>> @GET
>> @Path("/animals/")
>> public AnimalList getAnimals(){
>> AnimalList al = new AnimalList();
>> al.addAnimal(new Dog("Fifi"));
>> al.addAnimal(new Cat("Daisy"));
>> return al;
>> }
>>
>> @PUT
>> @Path("/animals/")
>> public Animal addAnimal(Animal a){
>> return a;
>> }
>>
>> .. where:
>>
>> @XmlRootElement(name="animalList")
>> public class AnimalList{
>> private List<Animal> animals = new ArrayList<Animal>();
>> ..
>> }
>>
>> @XmlRootElement(name="animal")
>> public class Animal {
>> private String name;
>> ..
>> }
>>
>> @XmlRootElement(name="cat")
>> public class Cat extends Animal {
>> ..
>> }
>>
>> @XmlRootElement(name="dog")
>> public class Dog extends Animal {
>> ..
>> }
>>
>> Cat and Dog classes need to be set up in the JAXB context, like
>> Paul wrote.
>
> Thanks, hopefully that example will help Ido.
>
> <snip>
>> Default JSON notation doesn't support property namespaces, so the
>> "xsi:type" property isn't passed to JAXB and the object
>> is deserialized as an instance of the superclass. Not sure
>> why the root element doesn't translate to the correct subclass
>> in this example, but even if it did, it wouldn't help in the
>> cases, where the subclass is not the root element but a
>> subproperty.
>>
>> Another example can be found in jersey issue 113:
>> https://jersey.dev.java.net/issues/show_bug.cgi?id=113
>>
>> Could passing the xsi:type from JSON to JAXB in de-serialization
>> be possible with the other JSON notations?
>>
>
> Jakub, what do you think?
I would bet badgerfish would work as this notation keeps
all of the XML info in JSON.
Can you try with JSONConfiguration.badgerFish().build() JSON config?
~Jakub
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>