From 95a39496902e831527e6f5dbe6a6a17c0eba9907 Mon Sep 17 00:00:00 2001 From: Fabien Crespel Date: Fri, 20 Dec 2024 23:53:44 +0100 Subject: [PATCH 1/2] Fix serialization of time_zone field in CompositeDateHistogramAggregationSource Signed-off-by: Fabien Crespel --- CHANGELOG.md | 1 + ...mpositeDateHistogramAggregationSource.java | 42 ++++++++++++++----- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5db3469860..6fe8fc723c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Removed ### Fixed +- Fixed serialization of `time_zone` field in `CompositeDateHistogramAggregationSource` ([#1362](https://github.com/opensearch-project/opensearch-java/pull/1362)) ### Security diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/aggregations/CompositeDateHistogramAggregationSource.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/aggregations/CompositeDateHistogramAggregationSource.java index 34fe20c093..9e67d4f493 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/aggregations/CompositeDateHistogramAggregationSource.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/aggregations/CompositeDateHistogramAggregationSource.java @@ -29,14 +29,15 @@ public class CompositeDateHistogramAggregationSource extends CompositeValuesSour @Nullable private final Long offset; - private final String zoneId; + @Nullable + private final String timeZone; private CompositeDateHistogramAggregationSource(Builder builder) { super(builder); this.calendarInterval = builder.calendarInterval; this.fixedInterval = builder.fixedInterval; this.offset = builder.offset; - this.zoneId = builder.zoneId; + this.timeZone = builder.timeZone; } public static CompositeDateHistogramAggregationSource of(Function> fn) { @@ -65,14 +66,22 @@ public final Time fixedInterval() { @Nullable public final Long offset() { return this.offset; + } + /** + * API name: {@code time_zone} + */ + public final String timeZone() { + return this.timeZone; } /** - * Required - API name: {@code zone_id} + * API name: {@code time_zone} + * @deprecated Use {@link #timeZone()} instead. */ + @Deprecated public final String zoneId() { - return this.zoneId; + return timeZone(); } /** @@ -103,8 +112,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } - generator.writeKey("zone_id"); - generator.write(this.zoneId); + if (this.timeZone != null) { + generator.writeKey("time_zone"); + generator.write(this.timeZone); + } } /** @@ -124,7 +135,8 @@ public static class Builder extends CompositeValuesSource.AbstractBuilder Date: Sat, 21 Dec 2024 18:40:01 +0100 Subject: [PATCH 2/2] Add test for CompositeDateHistogramAggregationSource Signed-off-by: Fabien Crespel --- ...iteDateHistogramAggregationSourceTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/_types/aggregations/CompositeDateHistogramAggregationSourceTest.java diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/aggregations/CompositeDateHistogramAggregationSourceTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/aggregations/CompositeDateHistogramAggregationSourceTest.java new file mode 100644 index 0000000000..8a9aaff79e --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/aggregations/CompositeDateHistogramAggregationSourceTest.java @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch._types.aggregations; + +import org.junit.Test; +import org.opensearch.client.opensearch.model.ModelTestCase; + +public class CompositeDateHistogramAggregationSourceTest extends ModelTestCase { + + @Test + public void testSerializeSpecificFields() { + String json = "{\"calendar_interval\":\"1d\",\"fixed_interval\":\"1d\",\"offset\":1,\"time_zone\":\"+01:00\"}"; + CompositeDateHistogramAggregationSource aggregation = fromJson(json, CompositeDateHistogramAggregationSource._DESERIALIZER); + assertEquals(json, toJson(aggregation)); + } + +}