# Java API vs Jackson dependencies : Can it be a problem?

**URL:** <https://discuss.elastic.co/t/java-api-vs-jackson-dependencies-can-it-be-a-problem/68460>\
**Category:** Elasticsearch\
**Created:** [December 8, 2016, 4:51pm UTC](https://discuss.elastic.co/t/java-api-vs-jackson-dependencies-can-it-be-a-problem/68460 "2016-12-08T16:51:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [December 8, 2016, 4:51pm UTC](https://discuss.elastic.co/t/java-api-vs-jackson-dependencies-can-it-be-a-problem/68460/1 "2016-12-08T16:51:32Z")

</div>

Hi all,

I have a Java Maven project with:

```
    <dependency>
		<groupId>org.elasticsearch</groupId>
		<artifactId>elasticsearch</artifactId>
		<version>2.4.2</version>
	</dependency>

```

I run a simple prepareIndex, where source is an HashMap, no special field:

```
				IndexResponse ir = client.prepareIndex(documentType.getIndexName(), documentType.getDocumentType(), Long.toString(2222222))
					.setSource(source)
					.get();

```

No problem here, ir.getShardInfo().getFailed() = 0, and my document is well indexed.

BUT, there is an error into the IndexResponse (I think it's when decoding the response):

```
  IndexResponse[index=myindex,type=mydoc,id=2222222,version=11,created=false,shards=Error building toString out of XContent: com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value
      at com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:1886)
      at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeFieldName(UTF8JsonGenerator.java:235)
      at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeFieldName(JsonXContentGenerator.java:152)
      at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:264)
      at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:255)
      at org.elasticsearch.common.xcontent.XContentBuilder.startObject(XContentBuilder.java:169)
      at org.elasticsearch.action.ActionWriteResponse$ShardInfo.toXContent(ActionWriteResponse.java:147)
      at org.elasticsearch.common.Strings.toString(Strings.java:1103)
      at org.elasticsearch.common.Strings.toString(Strings.java:1089)
      at org.elasticsearch.action.ActionWriteResponse$ShardInfo.toString(ActionWriteResponse.java:164)
      at java.lang.String.valueOf(String.java:2849)
      at java.lang.StringBuilder.append(StringBuilder.java:128)
      at org.elasticsearch.action.index.IndexResponse.toString(IndexResponse.java:118)
    ...
  ]

```

I found here a solution pretty recent: [http://stackoverflow.com/questions/39679400/elastic-search-bulk-index-java-api-not-working](http://stackoverflow.com/questions/39679400/elastic-search-bulk-index-java-api-not-working)

Here is another same problem, but only solved in 5x version: [https://github.com/elastic/elasticsearch/issues/20853](https://github.com/elastic/elasticsearch/issues/20853)

When I split dependencies, there is no more JsonGenerationException, but I wonder if it could be a problem to do not use the Jackson version "linked" to the Elasticsearch version.

**So my question is simple** : Should I stay with this error, or should I split dependencies ?

Thx,  
Xavier

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [December 8, 2016, 10:01pm UTC](https://discuss.elastic.co/t/java-api-vs-jackson-dependencies-can-it-be-a-problem/68460/2 "2016-12-08T22:01:11Z")

</div>

More info here : [https://github.com/elastic/elasticsearch/pull/21319](https://github.com/elastic/elasticsearch/pull/21319)

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 8, 2016, 10:17pm UTC](https://discuss.elastic.co/t/java-api-vs-jackson-dependencies-can-it-be-a-problem/68460/3 "2016-12-08T22:17:14Z")

</div>

Personally I'd work around the issue until you are ready to upgrade. If it isn't a big deal then I'd upgrade sooner rather than later because the 2.x -\> 5.x upgrade requires a full cluster restart. And because you are using the transport client it requires that your app upgrade as well.....

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [December 9, 2016, 8:06am UTC](https://discuss.elastic.co/t/java-api-vs-jackson-dependencies-can-it-be-a-problem/68460/4 "2016-12-09T08:06:45Z")

</div>

It seems that there is a quickfix applied in the 5.x :

> <https://github.com/elastic/elasticsearch/pull/21319/commits/5faf26da634017890d7f2beaff029331f7facfee>

Do you think it can/will be applied to the 2.4 branch ?

```
    @Override
    public String toString() {
        return "ShardInfo{" +
            "total=" + total +
             ", successful=" + successful +
             ", failures=" + Arrays.toString(failures) +
            '}';            
    }

```

Thank you !  
Xavier

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 9, 2016, 3:23pm UTC](https://discuss.elastic.co/t/java-api-vs-jackson-dependencies-can-it-be-a-problem/68460/5 "2016-12-09T15:23:50Z")

</div>

I don't think we have any plans to do so. We might, but I don't think so.

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [December 9, 2016, 5:02pm UTC](https://discuss.elastic.co/t/java-api-vs-jackson-dependencies-can-it-be-a-problem/68460/6 "2016-12-09T17:02:32Z")

</div>

To avoid the exception, my Maven is now:

```
    <jackson.version>2.7.8</jackson.version>

```

...

```
	<dependency>
		<groupId>org.elasticsearch</groupId>
		<artifactId>elasticsearch</artifactId>
		<version>2.4.2</version>
		<exclusions>
			<exclusion>
				<groupId>com.fasterxml.jackson.core</groupId>
				<artifactId>jackson-core</artifactId>
			</exclusion>
			<exclusion>
				<groupId>com.fasterxml.jackson.dataformat</groupId>
				<artifactId>jackson-dataformat-smile</artifactId>
			</exclusion>
			<exclusion>
				<groupId>com.fasterxml.jackson.dataformat</groupId>
				<artifactId>jackson-dataformat-yaml</artifactId>
			</exclusion>
			<exclusion>
				<groupId>com.fasterxml.jackson.dataformat</groupId>
				<artifactId>jackson-dataformat-cbor</artifactId>
			</exclusion>
		</exclusions>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-core</artifactId>
		<version>${jackson.version}</version>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.dataformat</groupId>
		<artifactId>jackson-dataformat-smile</artifactId>
		<version>${jackson.version}</version>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.dataformat</groupId>
		<artifactId>jackson-dataformat-yaml</artifactId>
		<version>${jackson.version}</version>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.dataformat</groupId>
		<artifactId>jackson-dataformat-cbor</artifactId>
		<version>${jackson.version}</version>
	</dependency>
```

---

<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:** [January 6, 2017, 5:02pm UTC](https://discuss.elastic.co/t/java-api-vs-jackson-dependencies-can-it-be-a-problem/68460/7 "2017-01-06T17:02:32Z")

</div>

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