0

I asked:

when geting objects from a Json with restlet how can I get different objects in case the Json chnges its structure

So I am implementing an abstract class with 2 sub classes as suggested in:

Answer

I Followed the documentation in jackson annotations: jackson-annotations and Annotation Type JsonTypeInfo

But I don't know how to: // Include Java class name ("com.myempl.ImplClass") as JSON property "class"

on the abstract class:

@JsonTypeInfo(use=Id.CLASS, include=As.PROPERTY, property="class")

I get errors:

  1. Id cannot be resolved to a variable
  2. As cannot be resolved to a variable

And in the subclasses:

@JsonTypeInfo(use=Id.NAME, include=As.WRAPPER_OBJECT)
@JsonSubTypes({com.smartenit.client.business.rest.CapabilityWhenReadingAllDevices.class,
    com.smartenit.client.business.rest.CapabilityWhenRequestingAttribute.class})

I get errors:

  1. Id cannot be resolved to a variable
  2. As cannot be resolved to a variable
  3. The value for annotation attribute JsonSubTypes.value must be some @com.fasterxml.jackson.annotation.JsonSubTypes.Type annotation
Community
  • 1
  • 1
juan Isaza
  • 3,646
  • 3
  • 31
  • 37

1 Answers1

0

I think the Jackson API has evolved. I've tried with the sample annotations (located on the abstract class) with restlet 2.2 (leveraging jackson 2.2):

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = As.PROPERTY, property = "@class")
@JsonSubTypes({ @Type(value = Impl1.class, name = "impl1"),
        @Type(value = Impl2.class, name = "impl2") })

Could you give it a try?

user229044
  • 232,980
  • 40
  • 330
  • 338
Thierry Boileau
  • 866
  • 5
  • 8