Skip to content

JacksonJaxbJsonProvider should use the real "value.getClass()" to build the root type #87

@NicoNes

Description

@NicoNes

Hi,

I saw your comment in the code (JacksonJaxbJsonProvider.writeTo() method) : /* * This is still not exactly right; should root type be * further specialized with 'value.getClass()'? Let's see * how well this works before trying to come up with more * complete solution. */ rootType = writer.getTypeFactory().constructType(genericType); so I suppose you already know the issue.

I have two types :

public abstract class Page<E> implements Iterator<E> {

    public static final String PREV_PAGE_REL = "prev";
    public static final String NEXT_PAGE_REL = "next";

    public final Link getPreviousPageLink() {
        return getLink(PREV_PAGE_REL);
    }

    public final Link getNextPageLink() {
        return getLink(NEXT_PAGE_REL);
    }

    abstract Link getLink(String rel);

}

and

@JsonPropertyOrder({ "entities", "links" })
@JsonAutoDetect(fieldVisibility = Visibility.ANY, creatorVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class PageImpl<E> extends Page<E> {

    public static final String PAGE_QUERY_PARAM = "page";
    public static final String PER_PAGE_QUERY_PARAM = "perPage";
    public static final String SORT_QUERY_PARAM = "sort";

    private List<E> entities;

    @JsonSerialize(contentUsing = JsonLinkSerializer.class)
    @JsonDeserialize(contentUsing = JsonLinkDeserializer.class)
    private final List<Link> links;

}

My service returns

//Runtime time of page can be either PageImpl or any other sub type I can determine at compile time

Page<Data> page = ...;
return Response.ok(new GenericEntity<Page<Date>>(page) {}).build();

The problem is that the all the annotations I put into PageImpl will not be taken into account for serialization.

Do you already have any fix or workaround ?

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions