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

objectMapper NPE on branch refactor/538/spike-to-seperate-models-and-dtos #635

Closed
who opened this issue Mar 30, 2015 · 9 comments
Closed

Comments

@who
Copy link
Contributor

who commented Mar 30, 2015

I have been working over the new documentation that @dilipkrish has been putting together for the Swagger 2.0 strategy.

However, I seem to hit a roadblock. When I start my app, my configuration class, annotated with @EnableSwagger2, kicks in. After my Docket instance is created in this class, DocumentationPluginsBootstrapper.onApplicationEvent.(ContextRefreshedEvent contextRefreshedEvent) kicks in to fire off a scanDocumentation call. Eventually, FieldModelPropertyProvider.beanDescription is called, but before FieldModelPropertyProvider.onApplicationEvent, which means FieldModelPropertyProvider.objectMapper is still null. When FieldModelPropertyProvider.beanDescription tries to invoke objectMapper.getSerializationConfig(), the NullPointerException is triggered.

@dilipkrish
Copy link
Member

@who do you have the repo for me to look at? Im interested in the configuration you have. I suspect you're missing an @EnableWebMvc in one of your configuration classes.

@who
Copy link
Contributor Author

who commented Mar 30, 2015

Unfortunately the codebase I'm working on isn't shareable at the moment.

However, your suspicion seems to be correct - I had a separate @Configuration class that was setting up my ObjectMapper, and it did not have the @EnableWebMvc annotation. After adding it, the application event is successfully fired with the ObjectMapper config, and I no longer see a NullPointerException in FieldModelPropertyProvider.beanDescription!

Are there any guidelines as to which @Configuration classes need the @EnableWebMvc in order to work with the new Swagger 2.0 strategy of Springfox?

@dilipkrish
Copy link
Member

@who Its also on my list to document. However, just to help people with the similar issues like you've had, could I ask you to provide a little bit of background, albeit with a contrived example to demonstrate your configuration setup?

Setting up the ObjectMapper has been one of the most contentious issues we've faced in the past. Since this is a different approach, we'd like to document gotchas.

@dilipkrish
Copy link
Member

@who Closing this as its no longer an issue

dilipkrish added a commit that referenced this issue Mar 31, 2015
How to override the model property datatypes
How to override the documentation endpoints
Also a stab at javadocs

relates to #635
@byshome
Copy link

byshome commented Jan 18, 2016

/**
* publishEvent ObjectMapperConfigured to OptimizedModelPropertiesProvider
*/
@PostConstruct
public void setObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    SimpleModule module = new SimpleModule();
    objectMapper.registerModule(module);

    ApplicationContext applicationContext = applicationContextUtil.getApplicationContext();
    ObjectMapperConfigured objectMapperConfigured = new ObjectMapperConfigured(applicationContext, objectMapper);
    applicationContext.publishEvent(objectMapperConfigured);
}

@ezraroi
Copy link

ezraroi commented Sep 15, 2016

Hi, i have this issue in Spring Boot application using Springfox 2.4

@dilipkrish
Copy link
Member

@ezraroi please use 2.5.0

@ezraroi
Copy link

ezraroi commented Sep 15, 2016

Looks like the swagger ui in version 2.5.0 is not working properly with spring boot... it is not displaying most of my endpoints although the json includes them all

@ezraroi
Copy link

ezraroi commented Sep 15, 2016

I am seeing:
Finished Loading Resource Information. Rendering Swagger UI...

forever....

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

4 participants