Skip to content

Related entity rendered differently depending on JPA fetch type [DATAREST-1494] #1813

Closed
@spring-projects-issues

Description

@spring-projects-issues

jvanheesch opened DATAREST-1494 and commented

Please see reference url for quick reproducer.

On branch mastercurl [http://localhost:8080/books/] results in

{
  "timestamp": "2020-03-12T20:48:22.082+0000",
  "status": 500,
  "error": "Internal Server Error",
  "message": "Type definition error: [simple type, class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.hateoas.CollectionModel[\"_embedded\"]->java.util.Collections$UnmodifiableMap[\"books\"]->java.util.ArrayList[0]->org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$PersistentEntityResourceSerializer$1[\"content\"]->com.github.jvanheesch.Book[\"author\"]->org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$PersistentEntityResourceSerializer$1[\"content\"]->com.github.jvanheesch.Author$HibernateProxy$Co1jR6qK[\"hibernateLazyInitializer\"])",
  "path": "/books/"
}

For us this is currently non-blocking, as we use the following workaround:

@Bean
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
    ObjectMapper objectMapper = builder.build();
    objectMapper.addMixIn(Object.class, IgnoreHibernatePropertiesInJackson.class);
    return objectMapper;
}

// https://stackoverflow.com/a/44152216/1939921
@JsonIgnoreProperties({"hibernateLazyInitializer"})
private static class IgnoreHibernatePropertiesInJackson {
}

This issue seems very similar to https://jira.spring.io/browse/DATAREST-1442, although

With FetchType.EAGER serialization does not fail but resulting JSON does contain unnecessary "_embedded" section.

seems not to apply here


Reference URL: https://github.com/jvanheesch/spring-data-rest-bytebuddyinterceptor

1 votes, 2 watchers

Metadata

Metadata

Assignees

Labels

status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions