# Elesticsaerch Java API - XContentBuilder::string()

**URL:** <https://discuss.elastic.co/t/elesticsaerch-java-api-xcontentbuilder-string/109597>\
**Category:** Elasticsearch\
**Created:** [November 29, 2017, 12:56pm UTC](https://discuss.elastic.co/t/elesticsaerch-java-api-xcontentbuilder-string/109597 "2017-11-29T12:56:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefaan\_Neyts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stefaan_neyts/32/24821_2.png) [@Stefaan\_Neyts](https://discuss.elastic.co/u/Stefaan_Neyts)\
**Post date:** [November 29, 2017, 12:56pm UTC](https://discuss.elastic.co/t/elesticsaerch-java-api-xcontentbuilder-string/109597/1 "2017-11-29T12:56:00Z")

</div>

Hi

Regarding the Elasticsearch Java API 6.0.0

The class org.elasticsearch.common.xcontent.XContentBuilder has a method string() and the signature says it throws an IOException. Here is the implementation:

```
/**
 * Returns a string representation of the builder (only applicable for text based xcontent).
 */
public String string() throws IOException {
    return bytes().utf8ToString();
}

```

The bytes() nor the utf8ToString() method declare to throw an IOException.  
And the string() method itself does not override from the Releasable nor Flushable interfaces which the XContentBuilder implements.

According to me, the string() method does not need to declare to throw an IOException. My question is whether it is possible to change the API accordingly?

At this moment, I've circumvented the need to catch the IOException by just calling bytes().utf8ToString() directly in stead of using the string() method.

Kind regards

Stefaan Neyts

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 1, 2017, 8:35am UTC](https://discuss.elastic.co/t/elesticsaerch-java-api-xcontentbuilder-string/109597/2 "2017-12-01T08:35:10Z")

</div>

Please create an issue or a PR in the Elasticsearch repo.

---

<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:** [December 29, 2017, 8:35am UTC](https://discuss.elastic.co/t/elesticsaerch-java-api-xcontentbuilder-string/109597/3 "2017-12-29T08:35:22Z")

</div>

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