leangen / graphql-spqr

Build a GraphQL service in seconds
Apache License 2.0
1.1k stars 182 forks source link

ClassCastException: ...AnnotatedTypeFactory$AnnotatedTypeBaseImpl -> AnnotatedParameterizedType (because of field of type Object) #350

Open cristian-spiescu opened 4 years ago

cristian-spiescu commented 4 years ago

I have started getting the following exception:

Caused by: java.lang.ClassCastException: class sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl cannot be cast to class java.lang.reflect.AnnotatedParameterizedType (sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl and java.lang.reflect.AnnotatedParameterizedType are in module java.base of loader 'bootstrap')
    at io.leangen.geantyref.GenericTypeReflector.mergeAnnotations(GenericTypeReflector.java:977)
    at java.base/java.util.stream.ReduceOps$2ReducingSink.accept(ReduceOps.java:123)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.reduce(ReferencePipeline.java:558)
    at io.leangen.graphql.metadata.TypedElement.<init>(TypedElement.java:28)
    at io.leangen.graphql.metadata.strategy.value.jackson.JacksonValueMapper$ElementFactory.fromProperty(JacksonValueMapper.java:267)
    at io.leangen.graphql.metadata.strategy.value.jackson.JacksonValueMapper.toInputField(JacksonValueMapper.java:117)
...

A breakpoint + inspect lead me to the source of this error, i.e. the following field:

@Column(columnDefinition = "text")
@Convert(converter = myPackage.JpaMapConverter.class)
protected Object data;

Adding @GraphQLIgnore seems to fix the issue. However a better error message would help a lot. However, I recall having discovered other fields of type Object, but if I'm not mistaking the message was mentioning something more explicit.

Thanks!

kaqqao commented 3 years ago

Any chance you provide a minimal example provoking this? Object types fields are actually supported just fine. What this sounds like is a field and its related getter/setter having different types. The exception says the types of related elements (fields and methods) could not be merged.