I have to deserialize my Java Object and I can't use static reference i.e TypeReference.
Like,
So, I am left with is generating the right Javatype using type factory, but somehow I am not able to get the syntax right.
Aforementioned are my Classes and Interfaces.
public interface Request {}
public interface Response {}
public class MyRequest implements Request {
int id;
//Getter //Setter
}
public class MyResponse implements Response {
int id;
//Getter //Setter
}
public class UberObject<S extends Request, T extends Response> implements Serializable {
private S request;
private T response;
//Getter//Setter
}
public class UberObjectWithId<S extends Request, T extends Response> extends UberObject<S, T> {
private int id;
//Getter //Setter
}
UberObjectWithId typereferencedObject =
objectmapperobject.readValue(serialisedUberObjectWithId,
new TypeReference<UberObjectWithId<MyRequest, MyResponse>>() {});
The above approach works but I can't use TypeReference because of the limitation mentioned in the above link.
I tried using the Typefactory to retrieve the JavaType but I am not able to get the syntax right.
JavaType type = mapper.getTypeFactory().constructParametrizedType(UberObjectWithId.class,
UberObject.class, Request.class, Response.class);
but the call fails
objectmapperobject.readValue(serialisedUberObjectWithId, type);
How can I resolve my particular problem?