-
Notifications
You must be signed in to change notification settings - Fork 40.6k
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
Hibernate @Enity annotation changes Jackson serialization behavior #2267
Comments
It appears to be @olivergierke it looks like this is expected behavior, do we need to provide a quick global opt-out property. @efenderbosch Are you actually using Spring Data Rest? If not you could try removing it from your classpath. You can also exclude |
BTW also tested with 1.1.10 so this isn't a recent regression. |
I'm using Spring Data Rest because it brings in spring-web (HttpStatus) and spring-hateos (PagedResources). Our app is a pretty basic RESTful service w/ JPA. If there's a different spring-boot-starter or combination that will provide this functionality, I can use that instead. |
I was hopeful that this would work, but it didn't: @Bean
@Primary
public RepositoryRestConfiguration repositoryRestConfiguration() {
RepositoryRestConfiguration repositoryRestConfiguration = new RepositoryRestConfiguration();
repositoryRestConfiguration.exposeIdsFor(Test.class);
return repositoryRestConfiguration;
} I'm not confident that my bean is replacing the default bean. If I leave off |
This does work, however: @Bean
@Primary
public RepositoryRestConfiguration repositoryRestConfiguration(PersistentEntities persistentEntities,
RepositoryRestConfiguration repositoryRestConfiguration) {
for (PersistentEntity<?, ?> persistentEntity : persistentEntities) {
repositoryRestConfiguration.exposeIdsFor(persistentEntity.getType());
}
return repositoryRestConfiguration;
} |
I'd like to make |
My comment above was with a view towards users declaring their own
@Configuration
class CustomRepositoryRestMvcConfiguration extends RepositoryRestMvcBootConfiguration {
@Override
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.exposeIdsFor(City.class);
}
} This allows you to use Spring Data REST's approach to customising the configuration while also taking advantage of Boot's auto-configuration – any |
@efenderbosch If you're not actually using Spring Data REST, but simply looking for a starter to pull in spring-web and spring-hateoas, we added |
Note that |
When an object is annotated with @entity, then Jackson doesn't serialize the id.
This will serialize to
Commenting out
@Entity
will fix the serialization:I've created a minimal project to demonstrate the problem here:
https://github.com/efenderbosch/spring-hibernate-jackson-error
Should I also submit this to the Hibernate project?
I'm using OpenJDK 1.7.0_65 on Ubuntu 14.04.
The text was updated successfully, but these errors were encountered: