簡體   English   中英

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:無法識別的字段“ g”

[英]com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field “g”

有人可以用下面的java pojo做些什么。 我越來越例外

傑森

    {
      "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個已知屬性:“ query”,“ vf”,“ ids“,” epoch“])在com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:51)在com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:731) .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;
        }
      }

    }

Scores類應該是靜態的(或是頂級類)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM