Skip to content

Registration of JsonbAdapter on target class #372

Open
@dblevins

Description

@dblevins

The proposal is to update Jakarta JSON Binding 3.0 section 4.7.1. Adapters so that an adapter can be registered on the adapted class itself. For example:

@JsonbTypeAdapter(EmailAddressAdapter.class)
public class EmailAddress {

    private String value;

    public EmailAddress(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }
}

And

public class EmailAddressAdapter implements JsonbAdapter<EmailAddress, String> {

    @Override
    public String adaptToJson(EmailAddress obj) {
        return obj.getValue();
    }

    @Override
    public EmailAddress adaptFromJson(String obj) {
        return new EmailAddress(obj);
    }
}

For the purposes specification backwards compatibility and the ability to override an adapter, the existing two forms would take precedence. This is consistent with the specification's requirement use of JsonbTypeAdapter on parameters be ignored if it the adapter is defined on a field or in the config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions