I am trying to introduce the JsonCreator with extra attributes: animalType.
But it seemed the Factory constructor is never being called?
*@JsonCreator*
*public static Animal factoryDataSource(@JsonProperty("animalType")
AnimalType animalType){*
* if (animalType == AnimalType.Dog){*
* return new Dog();*
* }*
* else{*
* return new Cat();*
* }*
*}*
By the way, I am working on AS 5.3.0. Appreciated for your advice.
Kind Regards, Wenxing
On Fri, Jan 13, 2017 at 9:35 AM, wenxing zheng <[email protected]>
wrote:
> Dear all,
>
> I have an interface to create a object, like the followings. My question
> is: *how to annotate the Animal and Dog/Cat to make sure the input
> "animal" can be the instance of Dog/Cat after de-serialization?*
>
> My expectation is that the service createAnimal can be used for all the
> sub-classes of Animal.
>
> public class Animal { // All animals have names, for our demo purposes...
> public String name;
> protected Animal() { }
> }
>
> public class Dog extends Animal {
> public double barkVolume; // in decibels
> public Dog() { }
> }
>
> public class Cat extends Animal {
> boolean likesCream;
> public int lives;
> public Cat() { }
> }
>
> @Path("/zoo")
> public interface ZooService{
> @POST
> @Path("/")
> @Produces(MediaType.APPLICATION_JSON)
> @Consumes(MediaType.APPLICATION_JSON)
> @CSDNSecure
> Response createAnimal(Animal animal);
> }
>
> Thanks, Wenxing
>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev