2017-02-20 88 views
0

我有下面這個類:解析蛇的情況下返回null

@JsonAutoDetect 
@JsonIgnoreProperties(ignoreUnknown = true) 
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) 
public class AggregationModel { 
    @JsonProperty(value = "doc_count_error_upper_bound") 
    private Integer docCountErrorUpperBound; 

    @JsonProperty(value = "sum_other_doc_count") 
    private Integer sumOtherDocCount; 

    @JsonProperty(value = "buckets") 
    private List<Bucket> buckets; 

    public Integer getDocCountErrorUpperBound() { 
     return docCountErrorUpperBound; 
    } 

    public void setDocCountErrorUpperBound(Integer docCountErrorUpperBound) { 
     this.docCountErrorUpperBound = docCountErrorUpperBound; 
    } 

    public Integer getSumOtherDocCount() { 
     return sumOtherDocCount; 
    } 

    public void setSumOtherDocCount(Integer sumOtherDocCount) { 
     this.sumOtherDocCount = sumOtherDocCount; 
    } 

    public List<Bucket> getBuckets() { 
     return buckets; 
    } 

    public void setBuckets(List<Bucket> buckets) { 
     this.buckets = buckets; 
    } 
} 

這裏的JSON:

{ 
    "took": 15, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 10, 
    "max_score": 0, 
    "hits": [] 
    }, 
    "aggregations": { 
    "group_by": { 
     "doc_count_error_upper_bound": 0, 
     "sum_other_doc_count": 0, 
     "buckets": [ 
      { 
       "key": 439, 
       "doc_count": 7, 
       "average": { 
       "value": 5 
       } 
      } 
     ] 
    } 
    } 
} 

只請考慮 「聚合」 的一部分。

只有桶正在返回正常,而其他兩個返回爲空。我不確定爲什麼會這樣。我正在使用fasterxml.jackson。*(版本2.8.4)。

請幫忙。 TIA。

+0

請發表[mcve]。 – shmosel

+0

發佈json。在這種形式下,這個問題是不負責任的。 – jakubbialkowski

+0

請再次檢查問題。 –

回答

0

我寫的測試用例使用Gson在後臺解析JSON,一旦我將它轉換爲Jackson,它就開始工作。

非常感謝。

相關問題