Finally, I've found the Mixin Annotations to solve the circular without touching the existing POJO.
There is a reference of Minin Annotations here: http://wiki.fasterxml.com/JacksonMixInAnnotations
The following is a brief steps to use Mixin:
Add ObjectMapper to your web-spring-servlet.xml
<bean id="myFrontObjectMapper" class="my.anying.web.MyObjectMapper"></bean> <mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="objectMapper" ref="myObjectMapper"></property> </bean> </mvc:message-converters> </mvc:annotation-driven>
Implement MyObjectMapper
public class MyObjectMapper extends ObjectMapper { public MyObjectMapper() { this.registerModule(new MixinModule()); } }
Implement MixinModule
public class MixinModule extends SimpleModule { private static final long serialVersionUID = 8115282493071814233L; public MixinModule() { super("MixinModule", new Version(1, 0, 0, "SNAPSHOT", "me.anying", "web")); } public void setupModule(SetupContext context) { context.setMixInAnnotations(Target.class, TargetMixin.class); } }
Done.
Now all annotations on TargetMixin class will be applied to Target class.