Search code examples
javaangularserializationdeserializationformarray

Send an object with nested list


I'm coding a webapplication that takes two array and a matrix from user using angular and then send them to java and then do some calculation, I'm using FormGroup for this webapplicaiton, at the end when user sends data to server the FormGroup values are something like this:

object {
targetFunctionValues= [1,2,3,4,5],
constraintsValues= [[1,2,3,4],[1,2,3,4]],
resultValues=[1,2,3,4]
}

I'm using FormGroup for "object" and FormArray for "list1", "matrix1", "list2". When data sends to server I get this error

Cannot deserialize value of type `java.lang.Double` from Object value (token `JsonToken.START_OBJECT`);

in server I created a class that looks like this :

public class MatricesValues {

    private List<Double> targetFunctionValues;

    private List<List<Double>> constraintsValues;

    private List<Double> resultValues;
}

and controller is like this:

@RestController
@RequestMapping("/value")
public class ValueController {

    @PostMapping("/send-data")
    public void sendDate(@RequestBody MatricesValues values){
        System.out.println(values.getTargetFunctionValues());
        System.out.println(values.getConstraintsValues());
        System.out.println(values.getResultValues());
    }

}

What can I do?


Solution

  • After a week, I got what I can do I can't send FormArray object contains FormControls I had to create another object that contains only values (Not other data related to FormControls in angular) And then I send that object and everything is fine Maybe in future can help someone