diff --git a/java-client/src/main/java/co/elastic/clients/elasticsearch/_types/mapping/Subobjects.java b/java-client/src/main/java/co/elastic/clients/elasticsearch/_types/mapping/Subobjects.java index 39ddfb48d..d9e9e6bb2 100644 --- a/java-client/src/main/java/co/elastic/clients/elasticsearch/_types/mapping/Subobjects.java +++ b/java-client/src/main/java/co/elastic/clients/elasticsearch/_types/mapping/Subobjects.java @@ -22,6 +22,8 @@ import co.elastic.clients.json.JsonEnum; import co.elastic.clients.json.JsonpDeserializable; import co.elastic.clients.json.JsonpDeserializer; +import co.elastic.clients.json.JsonpMapper; +import jakarta.json.stream.JsonGenerator; //---------------------------------------------------------------- // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. @@ -63,6 +65,17 @@ public String jsonValue() { return this.jsonValue; } - public static final JsonEnum.Deserializer _DESERIALIZER = new JsonEnum.Deserializer<>( + @Override + public void serialize(JsonGenerator generator, JsonpMapper params) { + if (this == Subobjects.True) { + generator.write(true); + } else if (this == Subobjects.False) { + generator.write(false); + } else { + generator.write(jsonValue()); + } + } + + public static final JsonEnum.Deserializer _DESERIALIZER = new JsonEnum.Deserializer.AllowingBooleans<>( Subobjects.values()); } diff --git a/java-client/src/test/java/co/elastic/clients/json/WithJsonTest.java b/java-client/src/test/java/co/elastic/clients/json/WithJsonTest.java index 02a9e15a0..135f7d1f4 100644 --- a/java-client/src/test/java/co/elastic/clients/json/WithJsonTest.java +++ b/java-client/src/test/java/co/elastic/clients/json/WithJsonTest.java @@ -25,6 +25,7 @@ import co.elastic.clients.elasticsearch._types.mapping.TextProperty; import co.elastic.clients.elasticsearch._types.query_dsl.Query; import co.elastic.clients.elasticsearch._types.query_dsl.TermQuery; +import co.elastic.clients.elasticsearch.cluster.GetComponentTemplateResponse; import co.elastic.clients.elasticsearch.core.IndexRequest; import co.elastic.clients.elasticsearch.core.SearchResponse; import co.elastic.clients.elasticsearch.indices.PutIndicesSettingsRequest; @@ -185,5 +186,69 @@ public void testExternalTaggedUnion() { .withJson(new StringReader("{\"id\": \"foo\"}"))); assertTrue(!withStoredScript.id().isEmpty()); } + + @Test + public void testBooleanEnum() { + + String templateJsonBooleanSubobject = """ + { + "component_templates": [ + { + "name": "test-template", + "component_template": { + "template": { + "mappings": { + "properties": { + "document": { + "subobjects": false, + "properties": { + "body.size": { + "type": "integer" + } + } + } + } + } + } + } + } + ] + } + """; + + String templateJsonStringSubobject = """ + { + "component_templates": [ + { + "name": "test-template", + "component_template": { + "template": { + "mappings": { + "properties": { + "document": { + "subobjects": "false", + "properties": { + "body.size": { + "type": "integer" + } + } + } + } + } + } + } + } + ] + } + """; + + GetComponentTemplateResponse respBool = GetComponentTemplateResponse.of(t -> t + .withJson(new StringReader(templateJsonBooleanSubobject))); + GetComponentTemplateResponse respString = GetComponentTemplateResponse.of(t -> t + .withJson(new StringReader(templateJsonStringSubobject))); + + // Asserting that both gets deserialized in the same way + assertEquals(respBool.toString(), respString.toString()); + } }