Repository navigation
feat: add support for virtual attributes on Records - #433
Conversation
fixes jakartaee#232 Co-authored-by: Martijn Dwars <[email protected]>
Co-authored-by-AI: IBM Bob (1.126.0+bob2.1.0)
|
|
||
| If `jakarta.json.bind.annotation.JsonbProperty` is specified on getter method, it is used only for serialization. If `jakarta.json.bind.annotation.JsonbProperty` is specified on setter method, it is used only for deserialization. | ||
|
|
||
| If `jakarta.json.bind.annotation.JsonbProperty` is specified on a virtual attribute method or component accessor method, then it is used only for serialization. |
There was a problem hiding this comment.
Clarified the meaning,
| If `jakarta.json.bind.annotation.JsonbProperty` is specified on a virtual attribute method or component accessor method, then it is used only for serialization. | |
| If `jakarta.json.bind.annotation.JsonbProperty` is specified on a virtual attribute method or component accessor method, then the customization defined by the `JsonbProperty` annotation applies only for serialization. |
but I'm confused how the serialized output can be used to deserialize the Java record again when one of its components needed by the default constructor is now absent. Is the expectation that this scenario would require a custom constructor?
There was a problem hiding this comment.
For example, if we had the following record:
public record Person(String firstName, String lastName) {
@JsonbProperty("name")
public String fullName() {
return firstName + " " + lastName;
}
}Then serialization of the an object would result in:
{
"firstName": "Jason",
"lastName": "Borune",
"name": "Jason Borune"
}
You would be able to deserialize this JSON object back into an equivalent record without a @JsonbCreator custom constructor. But there could be instances where serialization is asymmetric.
The same thing can be done with a regular Class if you put the @JsonbProperty on only the getter.
Same as the discussion you had here: #399 (comment)
Co-authored-by: Nathan Rauh <[email protected]>
njr-11
left a comment
There was a problem hiding this comment.
Some additional occurrences of the Borne vs Bourne misspelling - in case it matters. Feel free to ignore.
Co-authored-by: Nathan Rauh <[email protected]>
…rds/RecordVirtualAttributeTest.java Co-authored-by: Nathan Rauh <[email protected]>
Fixes #399
Fixes #232