将List <object>转换为List <hashmap <string,double >>以获得json数组

时间:2018-08-20 17:06:11

标签: java json

我有一个Json,如下所示:-

 {
      "componentModelData": {
        "modelNumber": "ABC",
        "modelName": "",
        "modelDescription": "",
        "modelVendor": null,
        "componentName": "HELO"
      },
      "revisionData": {
        "revisionName": "rev12",
        "revisionComment": "Comment",
        "modifiedBy": "2323553"
      }, 
      "configData": [{"nodes":2085,"FxPOS-SX":16.5051,"FxPOS-SY":11.0479,"FxPOS-SZ":115.3421,"FxPOS-SXY":-13.8094,"FxPOS-SYZ":36.0105
      },{"nodes":2085,"FxPOS-SX":16.5051,"FxPOS-SY":11.0479,"FxPOS-SZ":115.3421,"FxPOS-SXY":-13.8094,"FxPOS-SYZ":36.0105}]
    }

DataMapping.java

@Getter
@Setter
@JsonSerialize
@NoArgsConstructor
@AllArgsConstructor
public class DataMapping implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = -2635323042843403966L;
    @JsonProperty("componentModelData")
    @Valid
    public ComponentModelDTO componentModelDTO;
    @JsonProperty("revisionData")
    @Valid
    public RevisionDTO revisionDTO;
    @JsonProperty("configData")
    private List<Object> configData;
}

我想将configData列表转换为List<HashMap<String,Double>> list,其中String是像'nodes,FxPOS-SX,FxPOS-SY'这样的键,而value是它们各自的值。

有人可以帮我实现这个目标吗?

1 个答案:

答案 0 :(得分:2)

只需将List<Object>替换为List<Map<String,Double>>。杰克逊将为您完成艰苦的工作:

@JsonProperty("configData")
private List<Map<String, Double>> configData;