From 96f1688ef06f66b450b23ac0ef2d0b704481411c Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Tue, 22 Oct 2024 14:44:02 +1300 Subject: [PATCH] Fix deserializing `GeoBoundsAggregate` when `bounds` is not returned (#1238) * Fix deserializing `GeoBoundsAggregate` when `bounds` is not returned Signed-off-by: Thomas Farr * Update changelog Signed-off-by: Thomas Farr --------- Signed-off-by: Thomas Farr --- CHANGELOG.md | 1 + .../aggregations/GeoBoundsAggregate.java | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fd0194a05..b9015f9818 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Removed ### Fixed +- Fixed deserializing `GeoBoundsAggregate` when `bounds` is not returned by OpenSearch ([#1238](https://github.com/opensearch-project/opensearch-java/pull/1238)) ### Security diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/aggregations/GeoBoundsAggregate.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/aggregations/GeoBoundsAggregate.java index 02c093aa6e..ed5dab2959 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/aggregations/GeoBoundsAggregate.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/aggregations/GeoBoundsAggregate.java @@ -34,19 +34,20 @@ import jakarta.json.stream.JsonGenerator; import java.util.function.Function; +import javax.annotation.Nullable; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; import org.opensearch.client.json.JsonpMapper; import org.opensearch.client.json.ObjectBuilderDeserializer; import org.opensearch.client.json.ObjectDeserializer; import org.opensearch.client.opensearch._types.GeoBounds; -import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; // typedef: _types.aggregations.GeoBoundsAggregate @JsonpDeserializable public class GeoBoundsAggregate extends AggregateBase implements AggregateVariant { + @Nullable private final GeoBounds bounds; // --------------------------------------------------------------------------------------------- @@ -54,7 +55,7 @@ public class GeoBoundsAggregate extends AggregateBase implements AggregateVarian private GeoBoundsAggregate(Builder builder) { super(builder); - this.bounds = ApiTypeHelper.requireNonNull(builder.bounds, this, "bounds"); + this.bounds = builder.bounds; } @@ -71,18 +72,20 @@ public Aggregate.Kind _aggregateKind() { } /** - * Required - API name: {@code bounds} + * API name: {@code bounds} */ + @Nullable public final GeoBounds bounds() { return this.bounds; } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - super.serializeInternal(generator, mapper); - generator.writeKey("bounds"); - this.bounds.serialize(generator, mapper); + if (this.bounds != null) { + generator.writeKey("bounds"); + this.bounds.serialize(generator, mapper); + } } // --------------------------------------------------------------------------------------------- @@ -92,18 +95,19 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { */ public static class Builder extends AggregateBase.AbstractBuilder implements ObjectBuilder { + @Nullable private GeoBounds bounds; /** - * Required - API name: {@code bounds} + * API name: {@code bounds} */ - public final Builder bounds(GeoBounds value) { + public final Builder bounds(@Nullable GeoBounds value) { this.bounds = value; return this; } /** - * Required - API name: {@code bounds} + * API name: {@code bounds} */ public final Builder bounds(Function> fn) { return this.bounds(fn.apply(new GeoBounds.Builder()).build()); @@ -140,7 +144,5 @@ public GeoBoundsAggregate build() { protected static void setupGeoBoundsAggregateDeserializer(ObjectDeserializer op) { setupAggregateBaseDeserializer(op); op.add(Builder::bounds, GeoBounds._DESERIALIZER, "bounds"); - } - }