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

User registered Hibernate 5 Jackson module should be preferred over the one registered by default [DATAREST-899] #1268

Closed
spring-projects-issues opened this issue Sep 19, 2016 · 4 comments
Assignees
Labels
type: bug
Milestone

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Sep 19, 2016

Petar Tahchiev opened DATAREST-899 and commented

Hello,

before I was using Gosling SR4 and I was able to configure my own Hibernate5Module by overriding the configureJacksonObjectMapper method in RepositoryRestConfigurerAdapter like this:

@Override
public void configureJacksonObjectMapper(ObjectMapper objectMapper) {
    Hibernate5Module module = new Hibernate5Module();
    module.enable(Hibernate5Module.Feature.FORCE_LAZY_LOADING);
    module.disable(Hibernate5Module.Feature.USE_TRANSIENT_ANNOTATION);
    objectMapper.registerModule(module);
}

In there I specificly tell it to disable the USE_TRANSIENT_ANNOTATION because I want the fields in JPA annotated with @Transient to be return in the resulting json. However now that DATAREST-607 is fixed it registers the Hibernate5Module like this:

		public void registerModule(ObjectMapper mapper) {

			Hibernate5Module module = new Hibernate5Module();
			module.enable(Hibernate5Module.Feature.FORCE_LAZY_LOADING);

			mapper.registerModule(module);
		}

and even though I keep my old configuration it does not honor it so the @Transient fields are never returned in the json.

I will create a demo project to demonstrate this soon


Referenced from: commits 4eea46a, 4eeef2f

Backported to: 2.6 RC1 (Ingalls)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 19, 2016

Petar Tahchiev commented

Here's a demo project (with a test-case) which works in Gosling, but fails with Ingalls:

https://github.com/ptahchiev/demo-rest-problem

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 20, 2016

Petar Tahchiev commented

I think the problem lies in RepositoryRestMvcConfiguration:820:

Jackson2DatatypeHelper.configureObjectMapper(objectMapper);
// Configure custom Modules
configurerDelegate.configureJacksonObjectMapper(objectMapper);

It first goes through the spring-data hibernate5 module registration and then through the customer modules registration. I think the order must be reversed - first call the configurerDelegate.configureJacksonObjectMapper(objectMapper); to allow customers to register manually hibernate5 module with the settings they want, and then if it is not registered spring-data can register it

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 20, 2016

Petar Tahchiev commented

I have created a pull-request and it works:

#229

Please can you make it into the release on Wednesday?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 21, 2016

Oliver Drotbohm commented

Two things: please stop filing every issue as critical. You might consider them critical but they're usually not for the project overall. Especially with this one where the code causing the difficulties is not even contained in a released version. Hopper — by definition — can't be affected as we fixed DATAREST-607 for Ingalls only (to be shipped with RC1) exactly for that reason: to be able to mitigate potential regressions. So, thanks for playing with that stuff early. We will get this sorted out.

I guess we were under the assumption that a later addition of a Module would override the previous ones, but we can easily reverse this

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

No branches or pull requests

2 participants