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

Comments

Projects
None yet
4 participants
@who
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

This comment has been minimized.

Member

dilipkrish commented Mar 30, 2015

@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

This comment has been minimized.

Contributor

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

This comment has been minimized.

Member

dilipkrish commented Mar 31, 2015

@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

This comment has been minimized.

Member

dilipkrish commented Mar 31, 2015

@who Closing this as its no longer an issue

@dilipkrish dilipkrish closed this Mar 31, 2015

dilipkrish added a commit that referenced this issue Mar 31, 2015

Added more documentation related to ObjectMapper
How to override the model property datatypes
How to override the documentation endpoints
Also a stab at javadocs

relates to #635
@byshome

This comment has been minimized.

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

This comment has been minimized.

ezraroi commented Sep 15, 2016

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

@dilipkrish

This comment has been minimized.

Member

dilipkrish commented Sep 15, 2016

@ezraroi please use 2.5.0

@ezraroi

This comment has been minimized.

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

This comment has been minimized.

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