There are already the same issue on this resource. But the answer seems totally wrong for me, and don't work for me.
What a problem:
com.fasterxml.jackson.databind.JsonMappingException: Could not resolve type id 'MyRequest$GetAll' into a subtype of [simple type, class Request]
What I had:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@class")
@JsonSubTypes({ @JsonSubTypes.Type(value = MyRequest.GetAll.class)})
public class Request {
}
public class MyRequest extends Request {
public static class GetAll extends MyRequest {
public GetProfiles() {
}
}
What I've tried to do:
I tried to follow that advice, and move subtypes registration from annotations to java code:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@class")
public class Request {
}
public class MyRequest extends Request {
public static class GetAll extends MyRequest {
public GetProfiles() {
}
}
public class Utils {
private static final ObjectMapper mapper;
static {
mapper = new ObjectMapper();
registerSubtypes();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
}
private static registerSubtypes() { //REGISTER ALL SUBTYPES
mapper.registerSubtypes(MyRequest.GetAll.class);
//...
}
}
But no result, I still get an exception! The most curious in this situation is that it works fine on my local machine, but doesn't work after deployment.
Question:
What I should try to solve this problem?