Java API Client - GetResponse source null values converted to String "null"


I'm working with the new Java client, v8.3.3. I'm trying to do the following:

  • take a source from a GetResponse<JsonData>
  • create a Jakarta JsonObjectBuilder from that JsonData source
  • use an ObjectMapper to convert that JsonObject into a Java object (Foo)

My problem is that when converting from JsonObject to Foo, string fields that are null on the source (JsonValue.ValueType.NULL) are being set to String "null" on the Java object, when they ought to be just set to null.

Has anyone else encountered anything similar, or know of a way to handle this?

Can you provide a code snippets so that we have more details to reproduce the issue?

Also, you don't need to go from JsonData to JsonObject and finally Foo: you can directly call, which will use the object mapper associated to the Elasticsearch client.

I need to add fields (specifically for _index and _id) to the source, which is why I'm creating a JsonObjectBuilder first, before converting to Foo.

Here's a snippet of what I'm doing:

JsonObjectBuilder sourceBuilder = Json.createObjectBuilder(JsonData.of(item.result().source(), _mapper).toJson().asJsonObject());
sourceBuilder.add("_index", item.result().index()).add("_id", item.result().id());
return, Foo.class)

For example, if a String field name on Foo is null in the source, the resulting Foo object will have name set to "null", and not just null.