I try to learn JPA/Hibernate and last week I had a remarkable error:
"error": "Internal Server Error",
Type definition error: [simple type, class com.crud.demo.dto.EmployeeDto];
nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
No serializer found for class com.crud.demo.dto.EmployeeDto and no properties discovered
to create BeanSerializer
In my DTO I had only setters implemented, because if need getters than I thought I will do this from the Entity ==> the unique source.
After some hours I added in my DTO classes the getters and the getter for the id was immediately syntax highlighted --> collaring which means it is used. So Im searching where? And IntelliJ 'Find usage' I get the message "Usages or base methods of getId() Nothing found in 'All Places'"
Is that not strange? At least it is now working but I don't understand it...
Tim Holloway wrote:From your error message, I'm thinking that this wasn't actually a JPA problem but a problem with XML serialization.
Don't be fooled by the fasterxml part. Jackson is more famous for JSON serializing and deserializing.
By default, Jackson uses getters for object -> JSON and setters for JSON -> object. You can use several annotations to tweak this behaviour. One of them is @JsonAutoDetect which you can annotate a class with to tell Jackson to use fields, not methods.