Error in Jackson ObjectMapper parsing metrics configuration

331 views
Skip to first unread message

Adrian Riley

unread,
Sep 28, 2016, 11:22:01 AM9/28/16
to dropwizard-user
I've been try to upgrade from 0.9.1 to 1.0.0 (or 1.0.2). My config yaml file contains this metrics definition:

metrics:
  frequency: 60s
  reporters:
    - type: log
      logger: metrics


Now I'm getting this error when trying to start the server:

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.member.registration.MemberRegistrationServiceConfiguration["metrics"]->io.dropwizard.metrics.MetricsFactory["reporters"])

Tracing through the code in the debugger, I can see this error comes from the Jackson JSON ObjectMapper, specifically JaxbAnnotationIntrospector.findPropertyContentTypeResolver, which is called when type is a container or reference, but seems to only expect a container type. I am using Jackson 2.7.6. 

Anyone else seen this and has a solution?

Thanks

Adrian Riley

unread,
Sep 28, 2016, 11:31:44 AM9/28/16
to dropwizard-user
I have the jackson-datatype-jdk8 module loaded, not sure if that makes a difference.

Adrian Riley

unread,
Sep 29, 2016, 6:14:12 AM9/29/16
to dropwizard-user
Upgraded Jackson to 2.8.3, where the code around here has changed, but still got the same error.

Tatu Saloranta

unread,
Sep 29, 2016, 10:44:25 AM9/29/16
to dropwiz...@googlegroups.com
You'd need to include the stack trace: just generally indicating it comes from JaxbAnnotationIntrospector does not help a lot unfortunately. Exception does not look familiar.
Also, if possible, it'd be great to have a self-contained test for Jackson, since this sounds like either a Jackson bug (more likely), or problem with DW configuration setup (less likely).

-+ Tatu +-

ps. Not sure why `Optional` is used in configuration, seems like an anti-pattern to me. But perhaps that's what DropWizard configuration uses. If not, I'd just get rid of that to simplify handling, remove one possible source of issues.


On Thu, Sep 29, 2016 at 3:14 AM, Adrian Riley <adrian...@bjss.com> wrote:
Upgraded Jackson to 2.8.3, where the code around here has changed, but still got the same error.

--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adrian Riley

unread,
Sep 29, 2016, 10:51:02 AM9/29/16
to dropwizard-user
Use of Optional comes from the DropWizard configuration, this is not bespoke code. DropWizard masks the stack trace and instead gives that error message, but I've managed to extract it:


java.lang.RuntimeException: 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 com.google.common.base.Throwables.propagate(Throwables.java:160)
at io.dropwizard.testing.DropwizardTestSupport.startIfRequired(DropwizardTestSupport.java:196)
at io.dropwizard.testing.DropwizardTestSupport.before(DropwizardTestSupport.java:112)
at io.dropwizard.testing.junit.DropwizardAppRule.before(DropwizardAppRule.java:128)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
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

It does look like a Jackson issue, but I thought someone else might have experienced it in this scenario. I'll try to get a test for Jackson, but at the moment I've just parked the upgrade to get on with something else.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.

Tatu Saloranta

unread,
Sep 29, 2016, 11:15:47 AM9/29/16
to dropwiz...@googlegroups.com
Thanks: looks like a bug in jackson-module-jaxb-annotations.
Would you mind filing an issue at:


with cut'n pasted stack trace, mention of Jackson version used (2.7.5 or so I think)?

It's bit of an edge case, testing-wise, since it requires pieces from different modules, but I should be able to cobble together a test case with the info.

-+ Tatu +-


To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+unsubscribe@googlegroups.com.

Adrian Riley

unread,
Sep 29, 2016, 12:14:51 PM9/29/16
to dropwizard-user

Tatu Saloranta

unread,
Sep 29, 2016, 7:25:54 PM9/29/16
to dropwiz...@googlegroups.com
Thanks!

It turned out to be easy fix, just wish it had been uncovered earlier.
But will be included in 2.7.9 / 2.8.4.
It is possible to apply local fix by sub-classing JaxbAnnotationIntrospector, if anyone needs a work-around.

-+ Tatu +-


On Thu, Sep 29, 2016 at 9:14 AM, Adrian Riley <adrian...@bjss.com> wrote:
Reply all
Reply to author
Forward
0 new messages