Json映射到Java对象

时间:2017-06-07 05:26:01

标签: java json jackson

我从第三方服务提供商处获得了非常奇怪的Json对象,我遇到了实现相同问题的问题。下面是json对象。

{
  "signers": [
    "xyz@abc.com"
  ],
  "will_self_sign": true,
  "signatory": "nbc@hgj.com",
  "callback": "79474939202836",
  "comment": "Please sign the document",
  "expire_in_days": 10,
  "display_on_page": "all",
  "sign_coordinates": {
    "xyz@abc.com": {
      "1": [
        {
          "llx": 315,
          "lly": 20,
          "urx": 455,
          "ury": 60
        }
      ]
    },
    "xyz1@abc.com": {
      "1": [
        {
          "llx": 315,
          "lly": 20,
          "urx": 455,
          "ury": 60
        }
      ],
      "2": [
        {
          "llx": 315,
          "lly": 20,
          "urx": 455,
          "ury": 60
        }
      ],

    }
  }
}

我的Java对象如下所示

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DigioUpload {

    @JsonProperty(value = "signers", required = true)
    public List<String> signers;

    @JsonProperty(value = "will_self_sign")
    public Boolean willSelfSign;

    @JsonProperty("signatory")
    public String signatory;

    @JsonProperty("callback")
    public String callback;

    @JsonProperty("comment")
    public String comment;

    @JsonProperty(value = "expire_in_days")
    public Integer expireInDays;

    @JsonProperty("display_on_page")
    public String displayOnPage;

    @JsonProperty("sign_coordinates")

    public Map<String, SignDetails> signCoordinates;

}


public class SignDetails {

    public HashMap<String, SignCoordinates> details;

}

public class SignCoordinates {


    public Map<String, List<Coordinates>> coordinates;


}

class Coordinates {

    public Integer llx;
    public Integer lly;
    public Integer urx;
    public Integer ury;
}

无法在"xyz@abc.com"等动态键内映射对象。感谢任何帮助。

结果如下:

{"signers":["xyz@abc.com"],"will_self_sign":true,"signatory":"nbc@hgj.com","callback":"79474939202836","comment":"Please sign the document","expire_in_days":10,"display_on_page":"all","sign_coordinates":{"xyz@abc.com":{},"xyz1@abc.com":{}}}

1 个答案:

答案 0 :(得分:0)

没关系,我通过将此public Map<String, SignDetails> signCoordinates;转换为public Map<String, Object> signCoordinates来实现它;