Java 在函数fromJson之前向类注入一些属性
我想在导出fromJson之前将属性注入类Java 在函数fromJson之前向类注入一些属性,java,fromjson,Java,Fromjson,我想在导出fromJson之前将属性注入类 PrimitiveDocument document = null; document = (PrimitiveDocument) gson.fromJson(requestBody.toString(), AcceptPathDocument.class); 在AcceptPathDocument中,导入构造函数原语文档: if (!this.getApplicationTag().equals("")) { Database db = M
PrimitiveDocument document = null;
document = (PrimitiveDocument) gson.fromJson(requestBody.toString(), AcceptPathDocument.class);
在AcceptPathDocument中,导入构造函数原语文档:
if (!this.getApplicationTag().equals("")) {
Database db = Master.getDB(this.getApplicationTag());
try {
this.doc = db.createDocument();
this.setForm(this.getForm());
} catch (Exception e) {
e.printStackTrace();
}
}
但是我在requestBody中有applicationTag,所以当代码运行时,applicationTag是空的。如何在从JSON导出之前从requestbody注入应用程序标记?将AcceptPathDocument类分解为两个类可能会有所帮助。
这意味着首先将json转换为pojo,然后将此对象作为字段添加到第二个类中。类似于装饰模式。将AcceptPathDocument类分解为两个类可能会有所帮助。
这意味着首先将json转换为pojo,然后将此对象作为字段添加到第二个类中。像decorator模式。为什么不在反序列化之后设置表单?为什么不在反序列化之后设置表单?