com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段" g"

时间:2015-10-26 22:36:50

标签: java json jackson

请问下面的java pojo有什么问题。我异常

的Json

    {
      "epoch": 1407877412466,
      "ids": {
        "DUMMY1": "abcd",
        "DUMMY2": "pqrs"
      },
      "vf": {
        "ANS1": {
          "g": 0
        },
        "ANS2": {
          "g": 0
        },[...]
      }
    }

异常

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段" g" (类com.adtruth.zander.persistence.domain.VfdData),未标记为可忽略(4个已知属性:"查询"," vf"," ids" ," epoch"])     at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:51)     在com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:731)     在com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:915)     在com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1298)

POJO         包com.temp;

    import java.io.IOException;
    import java.io.Serializable;
    import java.util.Calendar;
    import java.util.Map;

    import com.fasterxml.jackson.annotation.JsonCreator;
    import com.fasterxml.jackson.annotation.JsonInclude;
    import com.fasterxml.jackson.annotation.JsonInclude.Include;
    import com.fasterxml.jackson.annotation.JsonProperty;
    import com.fasterxml.jackson.core.type.TypeReference;
    import com.google.common.collect.Maps;

    @JsonInclude(Include.NON_EMPTY)
    public class VfdData implements Serializable {

      @JsonProperty("epoch")
      private Long epoch = Calendar.getInstance().getTimeInMillis();

      @JsonProperty("query")
      private boolean query = false;

      @JsonProperty("ids")
      private Map<String, Object> ids = Maps.newHashMap();

      @JsonProperty("vf")
      private Map<String, Scores> vfScores = Maps.newLinkedHashMap();

      public Long getEpoch() {
        return epoch;
      }

      public void setEpoch(final Long epoch) {
        this.epoch = epoch;
      }

      public boolean isQuery() {
        return query;
      }

      public void setQuery(final boolean query) {
        this.query = query;
      }

      public Map<String, Object> getIds() {
        return ids;
      }

      public void setIds(final Map<String, Object> ids) {
        this.ids = ids;
      }

      public Map<String, Scores> getVfScores() {
        return vfScores;
      }

      public void setVfScores(final Map<String, Scores> vfScores) {
        this.vfScores = vfScores;
      }

      @JsonInclude(Include.NON_EMPTY)
      public class Scores {

        @JsonCreator
        public Scores() {
        }

        @JsonProperty("g")
        private Integer score;

        public Integer getScore() {
          return score;
        }

        public void setScore(final Integer score) {
          this.score = score;
        }
      }

    }

1 个答案:

答案 0 :(得分:0)

Scores类应该是静态的(或者是顶级类)。