英文:
Create Entity for Objects of same Type inside an Object
问题
我想使用Lombok表示一个复杂的JSON对象:
{
"property1": {
"type": "boolean",
"value": true,
"valueInfo": {
"info": "Hello"
}
},
"property2": {
"type": "string",
"value": "string234",
"valueInfo": {
"info": "World"
}
}
}
我已经成功创建了一个实体,可以使用外部键来表示复杂对象:
"properties": {
"property1": {
"type": "boolean",
"value": true,
"valueInfo": {
"info": "Hello"
}
},
"property2": {
"type": "string",
"value": "string234",
"valueInfo": {
"info": "World"
}
}
}
Lombok Java代码:
public class ComplexObject {
@JsonProperty("properties")
@Valid
private Map<String, PropertyValueDTO> variables = null;
}
public static class PropertyValueDTO {
@JsonProperty("type")
private ProcessVariableTypeEnum type;
@JsonProperty("value")
private String value;
@JsonProperty("valueInfo")
@Valid
private Map<String, Object> valueInfo = null;
}
是否可以在不需要键("properties")的情况下,从基本实体类中表示PropertyValueDTO
?
英文:
I want to represent a complex JSON Object using Lombok:
{
"property1": {
"type": "boolean",
"value": true,
"valueInfo": {
"info": "Hello"
}
},
"property2": {
"type": "string",
"value": "string234",
"valueInfo": {
"info": "World"
}
}
}
I was able to create an Entity when I can represent the complex object using an outer key:
"properties": {
"property1": {
"type": "boolean",
"value": true,
"valueInfo": {
"info": "Hello"
}
},
"property2": {
"type": "string",
"value": "string234",
"valueInfo": {
"info": "World"
}
}
}
Lombok Java Code:
public class ComplexObject {
@JsonProperty("properties")
@Valid
private Map<String, PropertyValueDTO> variables = null;
}
public static class PropertyValueDTO {
@JsonProperty("type")
private ProcessVariableTypeEnum type;
@JsonProperty("value")
private String value;
@JsonProperty("valueInfo")
@Valid
private Map<String, Object> valueInfo = null;
}
Is it possible to represent PropertyValueDTO
from a base entity class without the need for key (properties
)?
专注分享java语言的经验与见解,让所有开发者获益!
评论