We get some json string which needs to be converted into instance of a class which is part of some third party jar (which will be downloaded on the fly) which is not present in the class path.
and problem here is
We get below kind of Json
{
"a" :{
"nameType":"firstNameType"
},
"b":{
"nameType":"lastNameType"
}
}
And java classes class structure in jar is as follows
class A{
private String nameType;
// getters and setters are avaiable
}
class B{
private A a;
private A b;
// getters and setters
}
when we de-serialize above json to class B, value present in "b.b.nameType" is "firstNameType" instead of "lastNameType".
below is the code snippet.
ClassLoader classLoader = TestClass.class.getClassLoader();
ClassLoader loader =
new URLClassLoader(new URL[] { new
File("/Users/asdasd3414234d/Downloads/Default" +
".jar").toURI().toURL() }, classLoader);
ObjectMapper objectMapper = new ObjectMapper();
TypeFactory typeFactory =
TypeFactory.defaultInstance().withClassLoader(loader);
objectMapper.setTypeFactory(typeFactory);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,
false);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Object obj = objectMapper.readValue(content,Class.forName("defaulttermlibrary.AmlTransaction",true,loader));
System.out.println(obj);
could some one please help me