Skip to content

Commit

Permalink
Fix deserializing GeoBoundsAggregate when bounds is not returned (#…
Browse files Browse the repository at this point in the history
…1238)

* Fix deserializing `GeoBoundsAggregate` when `bounds` is not returned

Signed-off-by: Thomas Farr <[email protected]>

* Update changelog

Signed-off-by: Thomas Farr <[email protected]>

---------

Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia authored Oct 22, 2024
1 parent 3902aef commit 96f1688
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,28 @@

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;

// ---------------------------------------------------------------------------------------------

private GeoBoundsAggregate(Builder builder) {
super(builder);

this.bounds = ApiTypeHelper.requireNonNull(builder.bounds, this, "bounds");
this.bounds = builder.bounds;

}

Expand All @@ -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);
}
}

// ---------------------------------------------------------------------------------------------
Expand All @@ -92,18 +95,19 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
*/

public static class Builder extends AggregateBase.AbstractBuilder<Builder> implements ObjectBuilder<GeoBoundsAggregate> {
@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<GeoBounds.Builder, ObjectBuilder<GeoBounds>> fn) {
return this.bounds(fn.apply(new GeoBounds.Builder()).build());
Expand Down Expand Up @@ -140,7 +144,5 @@ public GeoBoundsAggregate build() {
protected static void setupGeoBoundsAggregateDeserializer(ObjectDeserializer<GeoBoundsAggregate.Builder> op) {
setupAggregateBaseDeserializer(op);
op.add(Builder::bounds, GeoBounds._DESERIALIZER, "bounds");

}

}

0 comments on commit 96f1688

Please sign in to comment.