Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 关于@JsonAnyGetter,@JsonAnySetter问题_Java_Json_Rest_Jackson_Fiddler - Fatal编程技术网

Java 关于@JsonAnyGetter,@JsonAnySetter问题

Java 关于@JsonAnyGetter,@JsonAnySetter问题,java,json,rest,jackson,fiddler,Java,Json,Rest,Jackson,Fiddler,我有一个类似这样的类: @JsonIgnoreProperties(ignoreUnknown = true) @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) public class XYZ { @JsonSerialize(using = ISODateSerializer.class) private Date startDate; @JsonSerialize(using = ISODateS

我有一个类似这样的类:

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class XYZ {

    @JsonSerialize(using = ISODateSerializer.class)
    private Date startDate;
    @JsonSerialize(using = ISODateSerializer.class)
    private Date endDate;
    private Map<String, Object> other = new HashMap<String, Object>();


    @JsonAnyGetter
    public Map<String, Object> any() {
      return other;
    }

    @JsonAnySetter
    public void set(String name, Object value) {
      other.put(name, value);
    }

    @JsonIgnore
    public void setJsonMap(Map<String, Object> other) {
      this.other = other;
    }

}
{
  "startDate": "2014-08-23",
  "endDate": "2014-08-24",
  "sumOfOrderValuesSquared": 178,
  "values": [
    {
      "position": 4,
      "value": "your statement closing date in <b>March 2015</b>.",
      "pValue": 0,
      "rawValue": "your statement closing date in <b>March 2015</b>.",
      "calculated": {
        "conversionRateStdErr": 0,
        "visitPercentage": 0.000016899313887856152,
        "conversionRate": 0
      }
    },
     {
      "position": 5,
      "value": "your statement closing date in <b>April 2015</b>.",
      "pValue": 0,
      "rawValue": "ass</b>.",
      "calculated": {
        "conversionRateStdErr": 0,
        "visitPercentage": 0.000012,
        "conversionRate": 0
      }
    }
  ]
}
@JsonIgnoreProperties(ignoreUnknown=true)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
公共类XYZ{
@JsonSerialize(使用=ISODateSerializer.class)
私人日期开始日期;
@JsonSerialize(使用=ISODateSerializer.class)
私人日期结束日期;
private-Map-other=new-HashMap();
@JsonAnyGetter
公共地图任意(){
归还他人;
}
@JSONANYSETER
公共无效集(字符串名称、对象值){
其他。put(名称、值);
}
@杰索尼奥雷
公共void setJsonMap(映射其他){
this.other=其他;
}
}
我还有一个json输出,如下所示:

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class XYZ {

    @JsonSerialize(using = ISODateSerializer.class)
    private Date startDate;
    @JsonSerialize(using = ISODateSerializer.class)
    private Date endDate;
    private Map<String, Object> other = new HashMap<String, Object>();


    @JsonAnyGetter
    public Map<String, Object> any() {
      return other;
    }

    @JsonAnySetter
    public void set(String name, Object value) {
      other.put(name, value);
    }

    @JsonIgnore
    public void setJsonMap(Map<String, Object> other) {
      this.other = other;
    }

}
{
  "startDate": "2014-08-23",
  "endDate": "2014-08-24",
  "sumOfOrderValuesSquared": 178,
  "values": [
    {
      "position": 4,
      "value": "your statement closing date in <b>March 2015</b>.",
      "pValue": 0,
      "rawValue": "your statement closing date in <b>March 2015</b>.",
      "calculated": {
        "conversionRateStdErr": 0,
        "visitPercentage": 0.000016899313887856152,
        "conversionRate": 0
      }
    },
     {
      "position": 5,
      "value": "your statement closing date in <b>April 2015</b>.",
      "pValue": 0,
      "rawValue": "ass</b>.",
      "calculated": {
        "conversionRateStdErr": 0,
        "visitPercentage": 0.000012,
        "conversionRate": 0
      }
    }
  ]
}
{
“起始日期”:“2014-08-23”,
“截止日期”:“2014-08-24”,
“sumOfOrderValuesSquared”:178,
“价值观”:[
{
“立场”:4,
“价值”:“您的报表截止日期为2015年3月。”,
“pValue”:0,
“原始价值”:“您的报表截止日期为2015年3月。”,
“计算”:{
“conversionRateStdErr”:0,
“访问率”:0.00001689931388785856152,
“转换率”:0
}
},
{
“立场”:5,
“价值”:“您的报表截止日期为2015年4月。”,
“pValue”:0,
“原始价值”:“ass.”,
“计算”:{
“conversionRateStdErr”:0,
“访问率”:0.000012,
“转换率”:0
}
}
]
}
现在我的问题是我需要迭代“值”对象。它是作为arraylist出现的,但是我不知道arraylist的类型以及如何迭代它,所以我无法迭代它

而且, 我正在使用httpClient-apacheapi进行服务器到服务器的rest调用,但它并没有陷入fiddler的陷阱。 我在Windows7机器上使用java应用程序。任何想法。
谢谢

为数组中的每个值设计一个类,并为其
列表使用一个实例变量

private List<Value> values;
私有列表值;
Jackson将自动反序列化。另外,当您使用时,请为
sumOfValuesSquared
使用另一个实例字段

此外,您可以忽略未知属性,但目前无法忽略任何属性,因为您有一个
JsonAnySetter


但是,如果您确实坚持使用这样的映射,请使用
ObjectNode
。至少您可以使用
JsonNode
为您所能做的一切来导航它。并用
@JsonUnwrap

对其进行注释。对于初学者来说,您应该设计出比这更好的类。“一刀切”的映射几乎从来都不是一个好的解决方案。是的,我不想修改这个类。我是JsonNode新手,您能详细解释一下如何迭代吗。谢谢