Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAX-RS: java.util.Optional is an unrecognized type #2143

Open
schmitzhermes opened this issue Mar 14, 2017 · 1 comment
Open

JAX-RS: java.util.Optional is an unrecognized type #2143

schmitzhermes opened this issue Mar 14, 2017 · 1 comment

Comments

@schmitzhermes
Copy link

schmitzhermes commented Mar 14, 2017

Hey folks,
I am using dropwizard in connection with Swagger (no Bundle or anything, just Swagger as a plain JAX-RS resource). I played around with java.util.Optional query params a bit. That works fine, but swagger seems to have a problem with Optional.

java.lang.IllegalArgumentException: Unrecognized Type: [null]
	at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1170)
	at com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:618)
	at com.fasterxml.jackson.databind.ObjectMapper.constructType(ObjectMapper.java:1543)
	at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:110)
	at io.swagger.converter.ModelConverterContextImpl.resolveProperty(ModelConverterContextImpl.java:80)
	at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:156)
	at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:110)
	at io.swagger.converter.ModelConverterContextImpl.resolveProperty(ModelConverterContextImpl.java:80)
	at io.swagger.converter.ModelConverters.readAsProperty(ModelConverters.java:58)
	at io.swagger.jaxrs.DefaultParameterExtension.createProperty(DefaultParameterExtension.java:204)
	at io.swagger.jaxrs.DefaultParameterExtension.extractParameters(DefaultParameterExtension.java:66)
	at io.swagger.jaxrs.ext.AbstractSwaggerExtension.extractParameters(AbstractSwaggerExtension.java:33)
	at io.swagger.jersey.SwaggerJersey2Jaxrs.extractParameters(SwaggerJersey2Jaxrs.java:63)
	at io.swagger.jaxrs.DefaultParameterExtension.handleAdditionalAnnotation(DefaultParameterExtension.java:185)
	at io.swagger.jaxrs.DefaultParameterExtension.extractParameters(DefaultParameterExtension.java:108)
	at io.swagger.jaxrs.ext.AbstractSwaggerExtension.extractParameters(AbstractSwaggerExtension.java:33)
	at io.swagger.jersey.SwaggerJersey2Jaxrs.extractParameters(SwaggerJersey2Jaxrs.java:63)
	at io.swagger.jaxrs.Reader.getParameters(Reader.java:1035)
	at io.swagger.jaxrs.Reader.parseMethod(Reader.java:974)
	at io.swagger.jaxrs.Reader.read(Reader.java:322)
	at io.swagger.jaxrs.Reader.read(Reader.java:172)
	at io.swagger.jaxrs.config.BeanConfig.scanAndRead(BeanConfig.java:242)
	at io.swagger.jaxrs.config.BeanConfig.setScan(BeanConfig.java:221)
	[...]
	at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:43)
	at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:85)
	at io.dropwizard.testing.DropwizardTestSupport.startIfRequired(DropwizardTestSupport.java:194)
	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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

This issue is caused because propType.containedType(0) resolves to null (find the source here). I also tried to add jackson in version 2.8.7 manually to the classpath, but it didn't help.

I already found a couple of issues regarding swagger and Optional, but they were all stating that this issue is resolved. Can you guys provide any help?

I'd be glad to help you out with further information.

@pjfanning
Copy link
Contributor

Have you tried registering the Jackson Java8 module(s)?

io.swagger.util.Json.mapper().registerModule(new Jdk8Module())

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

No branches or pull requests

2 participants