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

Hi,

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 someJsonData.to(Foo.class), 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 _modelMapper.map(sourceBuilder.build(), 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.

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