Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deserializing GeoBoundsAggregate when bounds is not returned #1238

Merged
merged 2 commits into from
Oct 22, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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");

}

}
Loading