-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Feature/extensions] Added default constructors for JSON parsing using Jackson #5369
Changes from all commits
8817116
420f8f9
63bd5b7
b577b57
e202a93
b17cd47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,9 +58,14 @@ public abstract class AggregationBuilder | |
BaseAggregationBuilder, | ||
Rewriteable<AggregationBuilder> { | ||
|
||
protected final String name; | ||
protected String name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand you had to remove the final because your no-arg constructor wasn't setting this, but I'm wondering if you can make the 1-arg ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have a 1-arg constructor but Jackson requires a default constructor for deserialization. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bigger question here is: if we are throwing an exception for a null name, how is it we are allowing Jackson to construct it with a null name? Specifically: if a null name is bad, we should not allow Jackson to create it null. If a null name is not bad, we should not be throwing an exception. As far as a solution if we think a null name is bad, we could just define the default constructor to call Alternately, and the point of my previous comment and SO link, there's a @JsonCreator
protected AggregationBuilder(@JsonProperty("defaultName") String name) {
if (name == null) {
throw new IllegalArgumentException("[name] must not be null: [" + name + "]");
}
this.name = name;
} |
||
protected AggregatorFactories.Builder factoriesBuilder = AggregatorFactories.builder(); | ||
|
||
/** | ||
* Constructor required for Jackson parsing | ||
*/ | ||
AggregationBuilder() {} | ||
|
||
/** | ||
* Constructs a new aggregation builder. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,13 @@ public SumAggregationBuilder(String name) { | |
super(name); | ||
} | ||
|
||
/** | ||
* Constructor required for Jackson parsing | ||
*/ | ||
private SumAggregationBuilder() { | ||
super(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should probably call |
||
} | ||
|
||
protected SumAggregationBuilder( | ||
SumAggregationBuilder clone, | ||
AggregatorFactories.Builder factoriesBuilder, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Preference) Would be nice to throw in a comment with the reason the constructor exists (required by Jackson). Repeat for the other 6 constructors in this PR. Although I notice in another constructor there's a
@JsonCreator
annotation which I presume does the same thing. What's the difference and why prefer one over the other?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments for all the constructors. Registering module in SDKClient here helped to remove @JsonCreator annotation.
JsonCreator just helps to tune the constructor for deserialization but default constructor is already taking care of it.