# Create java SearchResponse from Json

**URL:** <https://discuss.elastic.co/t/create-java-searchresponse-from-json/92721>\
**Category:** Elasticsearch\
**Created:** [July 11, 2017, 9:50pm UTC](https://discuss.elastic.co/t/create-java-searchresponse-from-json/92721 "2017-07-11T21:50:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ervin\_Puskar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ervin_puskar/32/17418_2.png) [@Ervin\_Puskar](https://discuss.elastic.co/u/Ervin_Puskar)\
**Post date:** [July 11, 2017, 9:50pm UTC](https://discuss.elastic.co/t/create-java-searchresponse-from-json/92721/1 "2017-07-11T21:50:20Z")

</div>

TLDR: Need to create java SearchResponse out of json string

I'm writing some unit tests in Java and I have a specific json string from a search response (one created in kibana) that I would like to use.

I need to create a SearchResponse (the java object) out of this json so that I can pass it to the same methods that the actual response from the client goes to.

I've tried using a jackson ObjectMapper and calling readValue or convertValue with no luck. From looking at some of the docs I think I need to use an XContentBuilder but I'm struggling to get it to work.

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 11, 2017, 11:01pm UTC](https://discuss.elastic.co/t/create-java-searchresponse-from-json/92721/2 "2017-07-11T23:01:11Z")

</div>

In coming 5.6 and 6.0, you will find I think some fromXContent() methods in the response objects.

I think that shouldn't achieve what you are looking for.

---

<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:** [August 8, 2017, 11:01pm UTC](https://discuss.elastic.co/t/create-java-searchresponse-from-json/92721/3 "2017-08-08T23:01:21Z")

</div>

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