I have been trying to get Jackson annotations working in the JBoss RestEasy application on a EAP 6.1.1 server. To be more exact I want to get the JacksonPolymorphicDeserialization working through there annotation like done here.
Now it seems simple enough but for some reason it’s not really working. I got the following code:
package example.model;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@type",visible = true)
@JsonSubTypes({@JsonSubTypes.Type(value = ImplementedRequest.class, name = "implementedrequest")})
public abstract class Request {
}
And the implementation of the abstract class:
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@type", visible = true)
public class ImplementedRequestextends Request {
@NotEmpty
private Person applicant;
private List<AbstractApplicationPart> applications;
}
I created a endpoint that makes a request and processes a request:
@Path("serviceRequest")
@Named("RequestResource")
@RequestScoped
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ValidateRequest
@IgnoreMediaTypes(MediaType.APPLICATION_JSON)
public class RequestResource {
public Boolean saveRequest( @Valid Request request, @Context HttpServletRequest req) throws JAXBException, AnError {
//Some awesome processing happens here
}
public Response getDummyData() {
// Creates and fills the ImplementedRequestextends
return result;
}
}
Now I also did some configuration and made sure I load the Jackson modules in Jboss with the war deployment. And made sure in my pom I have the same version as the Modules.
My expectation is now that if I do a call I get something like:
{
"applicant": { "name":"Dummy data", "age":31},
"applications": [ {"sport":"soccer"},{"sport":"judo"} ]
}
I was expecting to get a @type
name with the field implementedrequest
. This is my first attempt; eventually I also want to have the abstract array work like this. But I can't even get this working.