2015-10-26 87 views
0

請問下面的java pojo有什麼不對嗎?我得到一個例外com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:無法識別的字段「g」

的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個已知屬性:「query」,「vf」,「ids」,「epoch」]) at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:51 ) at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext .java:731) at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:915) at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1298 )

POJO package 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; 
     } 
     } 

    } 

回答

0

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

相關問題