I want to send a number (Java reference type Double) in my ResponseEntity:
@Controller
public class ProjectController {
@RequestMapping(value="/get/number")
public ResponseEntity<Double> getNumber(){
Double resp = new Double(654321.5432d);
ResponseEntity<Double> respEntity = new ResponseEntity<Double>(resp, HttpStatus.OK);
return respEntity;
}
}
In UI side, I am using AngularJS:
$scope.getNumber = function(){
DataNumber.getData({
},function(data){
console.log("Successfully Called get data number");
$scope.numberData = data;
$scope.showNumber = true;
},
function(){
console.log("Error Happened!");
});
};
The final output is like this:
{"0":"6","1":"5","2":"4","3":"3","4":"2","5":"1","6":".","7":"5","8":"4","9":"3","10":"2"}
I tried to see what received in browser, using javascript console, but the response is empty! As following image shows:
As you can see the Double is transformed to a JSON object! Each digit is now a field of a JSON object!
My Questions:
If we want to return a number as a response using SpringMVC, what is the standard way?
If the way I did it is correct, then:
how should I transfer this JSON object to a single number without coding! (I now how to write the code and get produce the number, I am looking for probable existing functions to do so.)
Why browser shows nothing in response!
Thanks in advance.