Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incompatible types for generic

I define jackoson serializer and add it to java class as JsonDeserialize like this:

@JsonDeserialize(using = ReportFilterDeserializer.class)

The compiler give this error:

error: incompatible types: Class<ReportFilterDeserializer> cannot be converted to Class<? extends JsonDeserializer<?>>
@JsonDeserialize(using = ReportFilterDeserializer.class)

The def of the annotation is:

public Class<? extends JsonDeserializer<?>> using() default JsonDeserializer.None.class;

If I remove the generic atttibute from ReportFilterDeserializer its passed compilation. I dont understand why the complier complain.

class ReportFilterDeserializer<T> extends JsonDeserializer<ReportFilter<T>> {
    @Override
    public ReportFilter<T> deserialize(JsonParser jsonParser,DeserializationContext arg1) throws IOException,JsonProcessingException {
        return null;
    }
}
like image 618
user1236097 Avatar asked Dec 22 '25 08:12

user1236097


1 Answers

That certainly seems very odd. About the only thing I can think of is accidental mixing of Jackson 1.x and 2.x annotation vs classes (org.codehaus.jackson is 1.x, com.fasterxml.jackson 2.x).

Does behavior differ on different JDKs (7 vs 8, for example -- maybe Java 8 has issues?)

like image 122
StaxMan Avatar answered Dec 23 '25 22:12

StaxMan