Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -63,6 +65,17 @@ public String jsonValue() {
return this.jsonValue;
}

public static final JsonEnum.Deserializer<Subobjects> _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<Subobjects> _DESERIALIZER = new JsonEnum.Deserializer.AllowingBooleans<>(
Subobjects.values());
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}