【发布时间】:2017-05-31 12:58:56
【问题描述】:
我已经在 JSON 响应中从 Schema 生成 POJO,编译并加载了从 POJO 生成的类,但是在反序列化 JSON 响应时,我没有可以反序列化的实际类。
MyClassLoader classLoader = new MyClassLoader(POJOGeneratorForJSON.class.getClassLoader());
Class parentJsonClass = classLoader.loadClass(topLevelclassName, classpathLoc);
ObjectMapper mapper = new ObjectMapper();
byte[] jsonBytes = generator.getBytesFromURL(source);
if(jsonBytes != null){
Object jsonObj = parentJsonClass.newInstance();
jsonObj = mapper.readValue(jsonBytes, Class.class);
}
我得到的例外是:“com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.Class out of START_OBJECT token”
我知道在mapper.readValue() 中我需要提供实际类作为第二个参数,但不知道如何。有人可以帮我解决问题吗?
【问题讨论】:
标签: java json reflection jackson classloader