Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Error in type resolution of reference type (Optional) #63

Closed
adrianriley opened this issue Sep 29, 2016 · 4 comments
Closed

Error in type resolution of reference type (Optional) #63

adrianriley opened this issue Sep 29, 2016 · 4 comments
Milestone

Comments

@adrianriley
Copy link

JaxbAnnotationIntrospector.findPropertyContentTypeResolver expects to be called with a container type, but is being called with a reference type (specifically an Optional) when parsing DropWizard configuration. Here's the stack trace

Caused by: io.dropwizard.configuration.ConfigurationParsingException: /home/developer/projects/employee-service/employee-service-parent/employee-service/target/test-classes/config.yml has an error:
  * Failed to parse configuration at: metrics.reporters; Must call method with a container type (got [reference type, class java.util.Optional<io.dropwizard.util.Duration<[simple type, class io.dropwizard.util.Duration]>])
 at [Source: N/A; line: -1, column: -1] (through reference chain: coop.employee.EmployeeServiceConfiguration["metrics"]->io.dropwizard.metrics.MetricsFactory["reporters"])

    at io.dropwizard.configuration.ConfigurationParsingException$Builder.build(ConfigurationParsingException.java:276)
    at io.dropwizard.configuration.YamlConfigurationFactory.build(YamlConfigurationFactory.java:152)
    at io.dropwizard.configuration.YamlConfigurationFactory.build(YamlConfigurationFactory.java:87)
    at io.dropwizard.cli.ConfiguredCommand.parseConfiguration(ConfiguredCommand.java:124)
    at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:72)
    at io.dropwizard.testing.DropwizardTestSupport.startIfRequired(DropwizardTestSupport.java:194)
    ... 18 more
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Must call method with a container type (got [reference type, class java.util.Optional<io.dropwizard.util.Duration<[simple type, class io.dropwizard.util.Duration]>])
 at [Source: N/A; line: -1, column: -1] (through reference chain: coop.employee.EmployeeServiceConfiguration["metrics"]->io.dropwizard.metrics.MetricsFactory["reporters"])
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:290)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:269)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
    at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
    at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:444)
    at com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._findDeserializer(TypeDeserializerBase.java:183)
    at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:106)
    at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:91)
    at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:142)
    at com.fasterxml.jackson.datatype.guava.deser.GuavaImmutableCollectionDeserializer._deserializeContents(GuavaImmutableCollectionDeserializer.java:44)
    at com.fasterxml.jackson.datatype.guava.deser.GuavaImmutableCollectionDeserializer._deserializeContents(GuavaImmutableCollectionDeserializer.java:14)
    at com.fasterxml.jackson.datatype.guava.deser.GuavaCollectionDeserializer.deserialize(GuavaCollectionDeserializer.java:103)
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:490)
    at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95)
    at com.fasterxml.jackson.module.afterburner.deser.SuperSonicBeanDeserializer.deserialize(SuperSonicBeanDeserializer.java:156)
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:490)
    at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:224)
    at com.fasterxml.jackson.module.afterburner.deser.SuperSonicBeanDeserializer.deserialize(SuperSonicBeanDeserializer.java:152)
    at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3779)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2050)
    at io.dropwizard.configuration.YamlConfigurationFactory.build(YamlConfigurationFactory.java:123)
    ... 22 more
Caused by: java.lang.IllegalArgumentException: Must call method with a container type (got [reference type, class java.util.Optional<io.dropwizard.util.Duration<[simple type, class io.dropwizard.util.Duration]>])
    at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.findPropertyContentTypeResolver(JaxbAnnotationIntrospector.java:567)
    at com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair.findPropertyContentTypeResolver(AnnotationIntrospectorPair.java:233)
    at com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair.findPropertyContentTypeResolver(AnnotationIntrospectorPair.java:233)
    at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findPropertyContentTypeDeserializer(BasicDeserializerFactory.java:1516)
    at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.resolveType(BasicDeserializerFactory.java:1886)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.constructSettableProperty(BeanDeserializerFactory.java:717)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:504)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:228)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:143)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:406)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:352)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
    ... 42 more


See https://groups.google.com/forum/#!topic/dropwizard-user/xgBAhXaqop0

@cowtowncoder
Copy link
Member

cowtowncoder commented Sep 29, 2016

Thank you for reporting this. Strange that it hasn't been hit before... seems like it would be occurring not infrequently.

And I assume this is with Jackson 2.7(.5)?

@cowtowncoder cowtowncoder changed the title Error in parsing JSON with reference type Error in type resolution of reference type (Optional) Sep 29, 2016
@cowtowncoder cowtowncoder modified the milestones: 2.7.8, 2.7.9 Sep 29, 2016
@adrianriley
Copy link
Author

It was 2.7.6 and 2.8.3, but I see you have covered both. Thanks

@robinst
Copy link

robinst commented Nov 23, 2016

Just hit this bug with spring-boot 1.4.0 (which has jackson 2.8.1). We're not using jaxb annotations, but org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration automatically adds the annotation inspector if it's on the classpath.

Bumping to spring-boot 1.4.2 and jackson 2.8.4 fixes the problem.

@tvaughan77
Copy link

FWIW, I had the same issue in Dropwizard (trying to upgrade from a 0.9.1 -> 1.0.5). While Dropwizard manages the jackson ecosystem to the 2.7.6 version, I found that forcing jackson up to 2.8.5 both solved this problem and kept everything else "holding together" pretty well too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants