Created
January 28, 2020 01:08
-
-
Save secondsun/bdbb235212399e75748cad3da8ac69ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ObjectMapper om = new ObjectMapper(); | |
//Basic construction and json serialization | |
var rec = new Record(42, "Hello, World!"); | |
System.out.println(rec.toString()); | |
System.out.println(om.writeValueAsString(rec)); | |
//Show Constructor | |
var recClass = Record.class; | |
for (RecordComponent recordComponent : recClass.getRecordComponents()) { | |
System.out.print("RecordComponent : "); | |
System.out.println(recordComponent.toString()); | |
for (Annotation ann : recordComponent.getAnnotations()) { | |
System.out.print("RecordComponent Annotation : "); | |
System.out.println(ann); | |
} | |
} | |
for (Constructor constructor : recClass.getConstructors()) { | |
System.out.print("Constructor : "); | |
System.out.println(constructor.toGenericString()); | |
for (Annotation ann : constructor.getDeclaredAnnotations()) { | |
System.out.print("Constructor Annotation : "); | |
System.out.println(ann); | |
} | |
for (Parameter param : constructor.getParameters()) { | |
System.out.print("Constructor Param : "); | |
System.out.println(param.toString()); | |
for (Annotation ann : param.getDeclaredAnnotations()) { | |
System.out.print("Constructor Param Annotation: "); | |
System.out.println(ann); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Record[id=42, text=Hello, World!] | |
{"id":42,"text":"Hello, World!"} | |
RecordComponent : int id | |
RecordComponent : java.lang.String text | |
Constructor : public dev.secondsun.recordstesting.Record(int,java.lang.String) | |
Constructor Annotation : @com.fasterxml.jackson.annotation.JsonCreator(mode=DEFAULT) | |
Constructor Param : int id | |
Constructor Param : java.lang.String text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
record Record(@JsonProperty("id") int id, @JsonProperty("text") String text) { | |
@JsonCreator | |
public Record{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment