我使用 Jackson 将我的应用程序模型序列化/反序列化为 JSON 和 XML(两者都需要)。
模型类:
@JacksonXmlRootElement
public class Data {
@JsonProperty("attributes")
@JsonDeserialize(using = AttributesDeserializer.class)
@JsonSerialize(using = AttributesSerializer.class)
@JacksonXmlElementWrapper
private Map<Key, Map<String, Attribute>> attributes;
Run Code Online (Sandbox Code Playgroud)
....
public class Key {
private Integer id;
private String name;
Run Code Online (Sandbox Code Playgroud)
....
public class Attribute {
private Integer id;
private Integer value;
private String name;
Run Code Online (Sandbox Code Playgroud)
我需要我的 JSON 看起来像这样:
{
"attributes": [
{
"key": {
"id": 10,
"name": "key1"
},
"value": {
"numeric": {
"id": 1,
"value": 100,
"name": "numericAttribute"
},
"text": {
"id": 2,
"value": …Run Code Online (Sandbox Code Playgroud)