Typefactory class at jackson has many deprecated methods inside it. I am using it like that:
public List<T> getX(Class<T> clz) {
ObjectMapper mapper = new ObjectMapper();
try {
String jsonData = mapper.writeValueAsString(data);
a = mapper.readValue(jsonData, TypeFactory.collectionType(List.class, clz));
} catch (Exception e) {
System.out.println(e.getMessage());
}
return a;// a is a global variable
}
and it warns me that collectionType is deprecated. What to use instead of it?
TypeFactory itself is NOT deprecated, just static methods; instance methods like “constructType” are available. So question is rather where do you get a TypeFactory instance to use.
Most often you get an instance from
ObjectMapperusing itsgetTypeFactorymethod; or fromSerializationConfig/DeserializationConfig. They carry an instance around.If none of these works, there is
TypeFactory.instanceas well that you can use.The reason for deprecation is that some extension modules will want to replace the standard factory: specifically, Scala module needs to extend type handling with Scala Collection (etc) types — these will not work by default, since Scala does not extend java.util versions.