Answer the question
In order to leave comments, you need to log in
How to return JSON from Rest controller?
I get json with matrix coefficients, I solve this matrix, but I don’t want to send it back, I get a 405 error
. Here is the Rest controller code
package com.solve.gauss.Controllers;
import com.solve.gauss.models.DataMatrix;
import com.solve.gauss.models.SLAU;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
@org.springframework.web.bind.annotation.RestController
public class RestController {
@PostMapping("/solve")
public HashMap<String, double[]> solve(@RequestBody DataMatrix data) {
SLAU system = new SLAU(data.size, data.matrix);
double[] x = system.solveMatrix();
for(int i=0; i < data.size; i++) System.out.print(x[i] + " ");
HashMap<String, double[]> json = new HashMap<>();
json.put("roots", x);
return json;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question