If you understand correctly, you want to serialize only when the lazy loaded collection is loaded, but you do not want serialization to call a selection.
If so, you should use jackson-datatype-hibernate and added as their docs already explain
public class HibernateAwareObjectMapper extends ObjectMapper {
public HibernateAwareObjectMapper() {
registerModule(new Hibernate4Module());
}
}
than register
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="path.to.your.HibernateAwareObjectMapper" />
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
The module has parameters Feature.FORCE_LAZY_LOADING, which indicates whether the object should be loaded and then serialized, which is set to false by default, which, I believe, is the behavior you need.
source
share