1

I'm using wildfly with resteasy + jackson and I've created a super abstract class named Participation, a subclass InnovationParticipation and a simple rest service. Here is the code:

//Super abstract class

@JsonTypeInfo(use=Id.NAME, property="theType", include = JsonTypeInfo.As.PROPERTY)
@JsonSubTypes({
    @JsonSubTypes.Type(value=InnovationParticipation.class, name="innovation"),
})
public abstract class Participation implements Serializable {

private static final long serialVersionUID = -8008289902553477716L;

    private String type;
    private String groupName;
    private String groupEmail;

    //Constructor, getters and setters

}

//subclass

public class InnovationParticipation extends Participation {

    private static final long serialVersionUID = -2843212924880669778L;

    private String area;
    private String innovationType;
    private String title;
    private String ideaDescription;

    //Constructor, getters and setters

}

//rest request

public class ParticipationRequest implements Serializable {

    private static final long serialVersionUID = -8919114519349685945L;

    private Participation participation;

}

//rest method

@POST
@Path("/participate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ParticipationResponse participate(ParticipationRequest request) {

    System.out.println("Yuppiiiii");

}

But Wildfly returns this error: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of beans.Participation, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information at [Source: io.undertow.servlet.spec.ServletInputStreamImpl@dd39841; line: 1, column: 18] (through reference chain: webservices.requests.ParticipationRequest["participation"])

Can anyone try to solve my problem?

Thanks in advance

Giamma
  • 808
  • 2
  • 10
  • 21
  • Can you post the body of your HTTP request please? – Hein Blöd Jul 21 '18 at 20:04
  • {participation: {"@theType":"innovation", "type": "blabla"}} – Giamma Jul 23 '18 at 08:18
  • I also tried {participation: {"theType":"innovation", "type": "blabla"}} – Giamma Jul 23 '18 at 08:19
  • That looks alright to me. I compared yours to my working (Jackson/Spring MVC) code and noticed one difference: instead of using the `name` attribute on the `@JsonSubTypes.Type` annotation in the base class, I put `@JsonTypeName` on the subclass. According to [this](https://stackoverflow.com/questions/33978725/jackson-why-do-i-need-jsontypename-annotation-on-subclasses), it should make no difference but you could give it a try. – Hein Blöd Jul 23 '18 at 17:41
  • Tried, nothing changes :( – Giamma Jul 24 '18 at 08:21

0 Answers0