jsonb-api icon indicating copy to clipboard operation
jsonb-api copied to clipboard

JsonbTypeAdapter missing ElementType.PARAMETER

Open dblevins opened this issue 6 years ago • 3 comments
trafficstars

It does not appear JsonbTypeAdapter can be used everywhere JsonbProperty can be used.

Imagine we have this field-based class

public class Source {

    @JsonbProperty("className")
    private String className;

    @JsonbProperty("path")
    @JsonbTypeAdapter(FileAdapter.class)
    private File path;

    @JsonbProperty("packageName")
    private String packageName;

    @JsonbProperty("imports")
    private List<String> imports;

    //...

We decide that we instead want to have final variables and use a constructor via JsonbCreator as such:

public class Source {

    private final String className;

    private final File path;

    private final String packageName;

    private final List<String> imports;

    @JsonbCreator
    public Source(@JsonbProperty("className") final String className,
                  @JsonbProperty("path") final File path,
                  @JsonbProperty("packageName") final String packageName,
                  @JsonbProperty("imports") final List<String> imports) {
        this.className = className;
        this.path = path;
        this.packageName = packageName;
        this.imports = imports;
    }
    //...

The limitation that prevents this from working appears to be that @JsonbTypeAdapter cannot "follow" the other annotations and be placed on the appropriate constructor parameter.

dblevins avatar Oct 08 '19 01:10 dblevins

+1 this is a sibling issue of https://github.com/eclipse-ee4j/jsonb-api/issues/197 (generally speaking we should ensure any field annotation supports parameter)

@dblevins workaround is to add -parameters to javac ;)

rmannibucau avatar Oct 08 '19 04:10 rmannibucau

+1 seems reasonable and straightforward to me

aguibert avatar Oct 22 '19 04:10 aguibert

With https://github.com/eclipse-ee4j/jsonb-api/issues/71 getting fixed, any chance of this getting in as well for the next version?

asvanberg avatar Oct 31 '21 15:10 asvanberg