# Json serialization exception using aggregation in java

**URL:** <https://discuss.elastic.co/t/json-serialization-exception-using-aggregation-in-java/152047>\
**Category:** Elasticsearch\
**Created:** [October 11, 2018, 12:29pm UTC](https://discuss.elastic.co/t/json-serialization-exception-using-aggregation-in-java/152047 "2018-10-11T12:29:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![saket\_satpute1](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@saket\_satpute1](https://discuss.elastic.co/u/saket_satpute1)\
**Post date:** [October 11, 2018, 12:29pm UTC](https://discuss.elastic.co/t/json-serialization-exception-using-aggregation-in-java/152047/1 "2018-10-11T12:29:47Z")

</div>

I was trying to create a rest api point for aggregation in elasticsearch using spring data elasticsearch. I am able to get the data in service layer but when controller (i.e. @RestController) is trying to return it to postman i am getting this error.

> Could not write JSON: For input string:  
> "bHRMZzc5aHdodDF5a0hOck15Lzl1UT09"; nested exception is  
> com.fasterxml.jackson.databind.JsonMappingException: For input string:  
> "bHRMZzc5aHdodDF5a0hOck15Lzl1UT09" (through reference chain:  
> org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl["aggregations"]-\>org.elasticsearch.search.aggregations.InternalAggregations["asMap"]-\>java.util.Collections$UnmodifiableMap["memberNumberToken"]-\>org.elasticsearch.search.aggregations.bucket.terms.StringTerms["buckets"]-\>java.util.ArrayList[0]-\>org.elasticsearch.search.aggregations.bucket.terms.StringTerms$Bucket["keyAsNumber"])

My Mapping file is this

```
{
  "transactions" : {
        "properties" : {
          
                "refernceId" : {
                  "type" :"text",
                  "index": true,
                  "store": true
                },
                "postingDate" : { 
                  "type" : "date",
                  "index": true,
                  "store": true,
                  "format" : "yyyy-MM-dd'T'HH:mm:ss'Z'"
                },
                "effectiveDate" : { 
                  "type" : "date",
                  "index": true,
                  "store": true,
                  "format" : "yyyy-MM-dd'T'HH:mm:ss'Z'"
                },
                "effectiveTime" : { 
                  "type" : "text",
                  "index": true,
                  "store": true
                },
                "effectiveEpochTime" : {
                  "type" : "long",
                  "index": true,
                  "store": true
                },
                "transactionAmount" : { 
                  "type" : "double",
                  "index": true,
                  "store": true
                },
                "transactionType" : { 
                  "type" : "keyword",
                  "index": true,
                  "store": true
                },
                "transactionDesc" : { 
                  "type" : "text",
                  "index": true,
                  "store": true
                },
                "transactionMemo" : {
                  "type" : "text",
                  "index": true,
                  "store": true
                },
                "transactionNumber" : { 
                  "type" : "text",
                  "index": true,
                  "store": true
                },
                "transactionTypeCode" : { 
                  "type" : "text",
                  "index": true,
                  "store": true
                },
                "transactionStatus" : {
                  "type" : "keyword",
                  "index": true,
                  "store": true
                },
                "principalAmount" : {
                  "type" : "double",
                  "index": true,
                  "store": true
              
                },
                "interest" : {
                  "type" : "text",
                  "index": true,
                  "store": true
                },
                "accountNumberToken" : { 
                  "type" : "keyword",
                  "index": true,
                  "store": true
                },
                "memberNumberToken" : {
                  "type" : "keyword",
                  "index": true,
                  "store": true
                },
                "accountType" : {
                  "type" : "keyword",
                  "index": true,
                  "store": true
                  
                 },
                "userSub" : { 
                  "type" : "keyword",
                  "index": true,
                  "store": true
                },
				"tenant" : { 
                  "type" : "keyword",
                  "index": true,
                  "store": true
                }
          
            }
        }
    }

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 8, 2018, 12:29pm UTC](https://discuss.elastic.co/t/json-serialization-exception-using-aggregation-in-java/152047/2 "2018-11-08T12:29:47Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
