I'm a beginner in java so i'm not really sure if the title is right but i've been trying to unmarshal a json string of which i won't know the type in advance.
public interface Dummy<T> {
T unmarShall(String item);
}
abstract class DummyAbstract implements Dummy<T> {
protected T unmarShall(String item){
ObjectMapper mapper = new ObjectMapper();
try {
T objectx = mapper.readValue(item, T);
return objectx;
}
}
}
}
As this method is expecting a Class as the second parameter
T objectx = mapper.readValue(item, T);
return objectx;
I've been reading about how to do this but can't really find a proper way to do this.
I would only call this method from an subclass like :
public class DummyImpl extends DummyAbstract<MyClass>{
}
I've been doing it with the class hardcoded into the implementation for now but that not DRY at all..
could that be done ?