# Java High Level REST Client: result casting

**URL:** <https://discuss.elastic.co/t/java-high-level-rest-client-result-casting/98960>\
**Category:** Elasticsearch\
**Created:** [August 31, 2017, 7:44am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-result-casting/98960 "2017-08-31T07:44:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sqshq](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sqshq](https://discuss.elastic.co/u/sqshq)\
**Post date:** [August 31, 2017, 7:44am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-result-casting/98960/1 "2017-08-31T07:44:30Z")

</div>

Hi,

I'm looking into Java High Level REST Client API and as far as I can see, there is to convinent ways to retrieve search result entity

- As json string: `getSourceAsString()`
- As map: `getSourceAsMap()`

However in Jest there is a way to cast search results right away:  
`List<Article> articles = result.getSourceAsObjectList(Article.class);`

Is this feature planned for implementation, or I just missed something?

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 11, 2017, 11:47am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-result-casting/98960/2 "2017-09-11T11:47:11Z")

</div>

Hi,  
you can also retrieve the source as bytes through the `getSourceRef` method. You are right though. Jest uses Gson to map json to user provided objects. The high-level REST client doesn't do that. We don't want to have extra dependencies at this point, rather reduce them instead.

Looking at the Jest code it should be easy to do this from your application:

```auto
String json = searchHit.getSourceAsString();
Article obj = gson.fromJson(json, Article.class);

```

We are not currently planning on adding this feature to the client. Do let us know if this is a blocker for you or whether it is a reasonable decision.

Cheers  
Luca

---

<div class="post-metadata">

**Author:** ![sqshq](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sqshq](https://discuss.elastic.co/u/sqshq)\
**Post date:** [October 4, 2017, 2:29pm UTC](https://discuss.elastic.co/t/java-high-level-rest-client-result-casting/98960/3 "2017-10-04T14:29:17Z")

</div>

I would say it is pretty reasonable, and it's not a blocker for me. Thank you for the response.

---

<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 1, 2017, 2:29pm UTC](https://discuss.elastic.co/t/java-high-level-rest-client-result-casting/98960/4 "2017-11-01T14:29:23Z")

</div>

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