-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add @Json.Creator #189
Add @Json.Creator #189
Conversation
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.
Just a note on changes I've made.
@@ -139,6 +139,16 @@ public boolean hasJsonAnnotation() { | |||
|
|||
@Override | |||
public void read() { | |||
|
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.
format
@@ -470,6 +481,8 @@ private void writeJsonBuildResult(Append writer, String varName) { | |||
// assuming name matches field here? | |||
writer.append(constructorParamName(name + (frequency == 0 ? "" : frequency.toString()))); | |||
} | |||
} else { |
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.
invert if
return element; | ||
} | ||
|
||
public VariableElement getElement() { |
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.
unused
jsonCreator = | ||
jsonCreator.or( | ||
() -> | ||
baseType.getEnclosedElements().stream() |
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.
refractor extract method
jsonCreator | ||
.map( | ||
ex -> { | ||
var mods = ex.getModifiers(); |
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.
refactor extract method
TypeReader(TypeElement baseType, TypeElement mixInType, NamingConvention namingConvention, String typePropertyKey) { | ||
private final boolean hasJsonCreator; | ||
|
||
TypeReader( |
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.
format
* @Json | ||
* public record Product( ... ) { | ||
* | ||
* public static Product factory(@Json.Alias("alias") String name){ |
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.
Missing annotation in example javadoc
We can annotate a constructor/factory method with
@Json.Creator
to get more control on how an object gets deserialized. (or use mix-ins to switch things up entirely)resolves #187