I need to make a call to a Java API from my Angular 2 application. I have utilized a TypeScript Map to send the request in the Java app.
The RestEndpoint in Java looks like this:
@PostMapping(value = Constants.PATH_BASE + "/sync/list")
public ResponseEntity<?> configureQueueList(@RequestBody Map<String,Integer> map){
//code here
}
However, I encountered an error when attempting to use the TypeScript map:
JSON parse error: Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token\n at [Source: java.io.PushbackInputStream@f6b068c; line: 1, column: 1]
When using Postman, I found that the following raw body works:
{ "key1":"value1", "key2":"value2", ..... ..... }
Edit 2: Type Script Endpoint
postMap(value:Map<string,number>){
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.url, value, options)
.map(success => success.status)
.catch(this.handleError);
}