Skip to content

feat: add support for virtual attributes on Records - #433

Merged
KyleAure merged 10 commits into
jakartaee:mainfrom
KyleAure:399-record-virtual-attributes
Sep 14, 2026
Merged

KyleAure merged 10 commits into
jakartaee:mainfrom
KyleAure:399-record-virtual-attributes

Conversation

@KyleAure

@KyleAure KyleAure commented Sep 3, 2026

Copy link
Copy Markdown
Member

Fixes #399
Fixes #232

@KyleAure KyleAure self-assigned this Sep 3, 2026
@KyleAure KyleAure added TCK documentation Involves the spec or javadocs labels Sep 3, 2026
@KyleAure KyleAure changed the title feat: add support for virtual attributes feat: add support for virtual attributes on Records Sep 3, 2026
Comment thread spec/src/main/asciidoc/jsonb.adoc Resolved
Comment thread spec/src/main/asciidoc/jsonb.adoc Resolved
Comment thread spec/src/main/asciidoc/jsonb.adoc Resolved
Comment thread spec/src/main/asciidoc/jsonb.adoc Resolved
Comment thread spec/src/main/asciidoc/jsonb.adoc Outdated

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified the meaning,

Suggested change
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?

@KyleAure KyleAure Sep 9, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread spec/src/main/asciidoc/jsonb.adoc Resolved
Comment thread spec/src/main/asciidoc/jsonb.adoc Resolved
Comment thread spec/src/main/asciidoc/jsonb.adoc Resolved
Comment thread spec/src/main/asciidoc/jsonb.adoc Resolved
Comment thread spec/src/main/asciidoc/jsonb.adoc Resolved

@njr-11 njr-11 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional occurrences of the Borne vs Bourne misspelling - in case it matters. Feel free to ignore.

@KyleAure
KyleAure merged commit 25aefa0 into jakartaee:main Sep 14, 2026
4 checks passed
@KyleAure
KyleAure deleted the 399-record-virtual-attributes branch September 14, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Involves the spec or javadocs TCK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Record must enable virtual attributes as POJO

2 participants