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) (#1241)

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



* Update changelog



---------


(cherry picked from commit 96f1688)

Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 80c3e22 commit 6ceae01
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 @@ -14,6 +14,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### 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 6ceae01

Please sign in to comment.