### 개발환경

* Spring MVC 3.2.0

* Hibernate 4.2.0.Final


### 문제발생

MVC 패턴에서 Controller 단에서 @PathVariable로 객체를 받아서 처리하려는 시도를 하면서 문제가 발생했다.


### 로그


HTTP Status 500 - No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.HashMap["result"]->com.sil.docsflow.web.common.Result["data"]->com.sil.docsflow.domain.company.User_$$_javassist_15["handler"])


type Exception report


message No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.HashMap["result"]->com.sil.docsflow.web.common.Result["data"]->com.sil.docsflow.domain.company.User_$$_javassist_15["handler"])


description The server encountered an internal error that prevented it from fulfilling this request.


exception


org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.HashMap["result"]->com.sil.docsflow.web.common.Result["data"]->com.sil.docsflow.domain.company.User_$$_javassist_15["handler"])

org.codehaus.jackson.map.ser.StdSerializerProvider$1.failForEmpty(StdSerializerProvider.java:89)

org.codehaus.jackson.map.ser.StdSerializerProvider$1.serialize(StdSerializerProvider.java:62)

org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:430)

org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:175)

org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142)

org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:430)

org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:175)

org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142)

org.codehaus.jackson.map.ser.MapSerializer.serializeFields(MapSerializer.java:287)

org.codehaus.jackson.map.ser.MapSerializer.serialize(MapSerializer.java:212)

org.codehaus.jackson.map.ser.MapSerializer.serialize(MapSerializer.java:23)

org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:600)

org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:280)

org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1345)

org.springframework.web.servlet.view.json.MappingJacksonJsonView.writeContent(MappingJacksonJsonView.java:292)

org.springframework.web.servlet.view.json.MappingJacksonJsonView.renderMergedOutputModel(MappingJacksonJsonView.java:247)

org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)

org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)

org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)

org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)

org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)

org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)

org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)

javax.servlet.http.HttpServlet.service(HttpServlet.java:621)

org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)

javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)

org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)

org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.34 logs.


Apache Tomcat/7.0.34


### 해결방법

* 참조페이지 : [Strange Jackson exception being thrown when serializing Hibernate object](http://stackoverflow.com/questions/4362104/strange-jackson-exception-being-thrown-when-serializing-hibernate-object)


### 나름 분석

하이버네이트에 의해 영속화된 객체에 hadler 와 hibernateLazyInitializer 의 필드가 생성되는 것으로 보인다. 이렇게 영속화된 객체를 JSON으로 직렬화 하는 과정에서 hadler 가 lazy로 처리되어 있어서 발생하는 문제가 아닌가 추측해본다.


+ Recent posts