# Getting the Object from searchResponse

**URL:** <https://discuss.elastic.co/t/getting-the-object-from-searchresponse/230727>\
**Category:** Elasticsearch\
**Created:** [May 1, 2020, 3:16pm UTC](https://discuss.elastic.co/t/getting-the-object-from-searchresponse/230727 "2020-05-01T15:16:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siddharth1010](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@Siddharth1010](https://discuss.elastic.co/u/Siddharth1010)\
**Post date:** [May 1, 2020, 3:16pm UTC](https://discuss.elastic.co/t/getting-the-object-from-searchresponse/230727/1 "2020-05-01T15:16:51Z")

</div>

I am trying to retrieve the Object from my searchresponse which I obtained through

`searchResponse = restHighLevelClient.search(searchRequest);`

I am using the following method

```
    SearchHit[] result = searchResponse.getHits().getHits();

    List<SearchHit> result2 = Arrays.asList(result);

    List<CheckoutCartActivity> result3 = new ArrayList<>();

    for (SearchHit searchHit : result2)
    {
        Map<String, Object> resultMap = searchHit.getSourceAsMap();
        System.out.println("resultMap is " + resultMap);
        result3.add(objectMapper.convertValue(resultMap,CheckoutCartActivity.class));
    }

       return result2;

```

For which I am getting NullPointerException at

`result3.add(objectMapper.convertValue(resultMap,CheckoutCartActivity.class));`

Can you please help me with this.

Is there any alternate and better way to retrieve the Class Object from searchResponse ?

---

<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:** [May 29, 2020, 3:16pm UTC](https://discuss.elastic.co/t/getting-the-object-from-searchresponse/230727/2 "2020-05-29T15:16:51Z")

</div>

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