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 serialization of time_zone field in CompositeDateHistogramAggregationSource #1362

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 @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Builder, ObjectBuilder<CompositeDateHistogramAggregationSource>> fn) {
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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);
}
}

/**
Expand All @@ -124,7 +135,8 @@ public static class Builder extends CompositeValuesSource.AbstractBuilder<Builde
@Nullable
private Long offset;

private String zoneId;
@Nullable
private String timeZone;

/**
* API name: {@code calendar_interval}
Expand All @@ -151,12 +163,20 @@ public final Builder offset(Long value) {
}

/**
* Required - API name: {@code zone_id}
* API name: {@code time_zone}
*/
public final Builder timeZone(String value) {
this.timeZone = value;
return this;
}

/**
* API name: {@code time_zone}
* @deprecated Use {@link #timeZone(String)} instead.
*/
@Deprecated
public final Builder zoneId(String value) {
this.zoneId = value;
return this;
return timeZone(value);
}

/**
Expand Down Expand Up @@ -192,7 +212,7 @@ protected static void setupCompositeDateHistogramAggregationSourceDeserializer(
op.add(Builder::calendarInterval, Time._DESERIALIZER, "calendar_interval");
op.add(Builder::fixedInterval, Time._DESERIALIZER, "fixed_interval");
op.add(Builder::offset, JsonpDeserializer.longDeserializer(), "offset");
op.add(Builder::zoneId, JsonpDeserializer.stringDeserializer(), "time_zone");
op.add(Builder::timeZone, JsonpDeserializer.stringDeserializer(), "time_zone");
}

}
Original file line number Diff line number Diff line change
@@ -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));
}

}
Loading