我需要获取JSON输入Pojo实例,我使用Jackson 2库,下面的readValue方法可以使用typeReferencing反序列化:
POJO_ClassName p = mapper.readValue(new TypeReference< POJO_ClassName >() {});
Run Code Online (Sandbox Code Playgroud)
但问题是,作为POJO被创建并加载在运行时动态,我怎么JSON到POJO实例/对象,因为我没有对上述说法完全限定类(POJO_ClassName)的名字吗?
注意:我使用jsonSchema2pojo库POJO在运行时生成类.
这是代码片段,我POJO用于JSON 在运行时生成并尝试
String classPath="com.EnrichmentService.Thread72";
String classLocation = System.getProperty("user.dir")
+ "/src/main/java"; JCodeModel codeModel = new JCodeModel();
final RuleFactory ruleFactory = new RuleFactory(config,
new Jackson2Annotator(config), new SchemaStore());
final SchemaMapper mapperSchema = new SchemaMapper(ruleFactory,
new SchemaGenerator());
mapperSchema.generate(codeModel, "EsRootDoc",classPath, json);
codeModel.build(new File(classLocation)); // generates pojo classes
// Till above jsonSchema2Pojo pojo generation all …Run Code Online (Sandbox Code Playgroud)