I am currently working with an object array that needs to be transformed before it is sent to the controller.
Here is the Angular code snippet I am using:
sourceObjArray: SourceObject[] = [..];
targetObjArray: SourceObject[]= [];
targetObjArray = object.assign(sourceObjArray);
// when i change target object it also causes source object to change
transformSourceObject(targetObjArray)
After some testing, I found a solution that works better:
targetObjArray = object.assign({}, sourceObjArray);
// when i call transform it does not affect source object :)
transformSourceObject(targetObjArray)
However, this new approach has led to a specific issue:
Could not read document: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: java.io.PushbackInputStream@302753d0; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: java.io.PushbackInputStream@302753d0; line: 1, column: 1]
My controller method signature looks like this:
@RequestMapping(.., method=RequestMethod.POST)
public save(@RequestBody List<Object>, BindResult bindResult){}