I'm trying to update an object using REST controller in Spring 3,Jackson 4.0, using the PUT method.
We have a Container class with 4 properties one to many relationships to Container.
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="@Id",scope = Container.class)
public class Container implements Comparable, Serializable {
private int containerId;
.
.
.
private Set<Container> containers;
private Collection<ImagePerContainer> imageControls;
private Collection<TextControl> textControls;
private Collection<PromoControl> promoControls;
private Collection<WebSource> webSourceControls;
}
Each one of this Objects (childs) have a reference to Container (father), like this:
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="@Id",scope = TextControl.class)
public class TextControl implements Serializable {
.
.
.
private int textControlId;
private String textControlName;
private Container container;
.
.
.
}
Im trying to update the object when my angularjs app modifes the model using $resources PUT request. The first time it saves succesfully, but the second time I get a 400 response from the server, which logs this error:
HandlerMethod details:
Controller [com.bamboo.catW3.web.json.ContainerController]
Method [public org.springframework.http.ResponseEntity<com.bamboo.catW3.domain.Container> com.bamboo.catW3.web.json.ContainerController.updateContainer(int,com.bamboo.catW3.domain.Container)]
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Already had POJO for id (java.util.UUID) [com.fasterxml.jackson.annotation.ObjectIdGenerator$IdKey@8adc3c85] (through reference chain: com.bamboo.catW3.domain.Container["@Id"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Already had POJO for id (java.util.UUID) [com.fasterxml.jackson.annotation.ObjectIdGenerator$IdKey@8adc3c85] (through reference chain: com.bamboo.catW3.domain.Container["@Id"])
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:171)
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.read(MappingJackson2HttpMessageConverter.java:163)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:135)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:180)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:95)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:123)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
If I update another Container it works also the first time, but if I modified again and try to update it gives me the same 400 error. It doesn't even enter the controller. If I restart the server, then it lets me update the object one time, and it stops working again.
Why does it work the first time only ? How can I fix this ?