Jackson is throwing a weird exception that I don\'t know how to fix. I\'m using Spring, Hibernate and Jackson.
I have already considered that lazy-loading is causing
Also you can make your domain object Director final. It is not perfect solution but it prevent creating proxy-subclass of you domain class.
I had the same error message from spring's @RestController
. My rest controller class was using spring's JpaRepository
class and by replacing repository.getOne(id)
method call with repository.findOne(id)
problem was gone.
I am New to Jackson API, when i got the "org.codehaus.jackson.map.JsonMappingException: No serializer found for class com.company.project.yourclass" , I added the getter and setter to com.company.project.yourclass, that helped me to use the ObjectMapper's mapper object to write the java object into a flat file.
I had a similar problem with lazy loading via the hibernate proxy object. Got around it by annotating the class having lazyloaded private properties with:
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
I assume you can add the properties on your proxy object that breaks the JSON serialization to that annotation.
Avoid Jackson serialization on non fetched lazy objects
i got the same error, but with no relation to Hibernate. I got scared here from all frightening suggestions, which i guess relevant in case of Hibernate and lazy loading... However, in my case i got the error since in an inner class i had no getters/setters, so the BeanSerializer could not serialize the data...
Adding getters & setters resolved the problem.
It's not ideal, but you could disable Jackson's auto-discovery of JSON properties, using @JsonAutoDetect
at the class level. This would prevent it from trying to handle the Javassist stuff (and failing).
This means that you then have to annotate each getter manually (with @JsonProperty
), but that's not necessarily a bad thing, since it keeps things explicit.