I'm trying to deserialize JSON Array, which is persisted into my MongoDB, to a Java object by using Jackson
. I found many tutorials mentioned to handle this polymorphism by adding:
@JsonTypeInfo(use=Id.CLASS,property="_class")
to a Super-class
. However, in my case, I can't be able to modify the Super-class
. So, are there some solutions to solve it without modifying the Super-class
? Here is my code:
public class User {
@JsonProperty("_id")
private String id;
private List<Identity> identities; // <-- My List contains objects of an abstract class; Identity
public User(){
identities = new ArrayList<Identity>();
}
public static Iterable<User> findAllUsers(){
return users().find().as(User.class); // Always give me the errors
}
/*More code*/
}
It always give me the error - Can not construct instance of securesocial.core.Identity, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
.