I'm trying to make a POST request to my API with the following Request Bodies:
{
"data": [
{
"source": "A",
"target": "B",
"distance": 10
},
{
"source": "A",
"target": "C",
"distance": 15
}
]
}
and
{
"data": [
{
"source": "A", "target": "B", "distance": 6
},
{
"source": "A", "target": "E", "distance": 4
}
]
}
The first one works, but the second one doesn't, and returns the following error:
"message": "JSON parse error: Unexpected character ('' (code 8203 / 0x200b)): was expecting double-quote to start field name; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('' (code 8203 / 0x200b)): was expecting double-quote to start field name\n at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 5]"
That's my Controller's POST function:
@PostMapping()
public ResponseEntity<Graph> saveGraph(@RequestBody Graph graph){
System.out.println(graph);
Graph obj = graphService.saveGraph(graph);
return ResponseEntity.status(HttpStatus.CREATED).body(obj);
}
Why is that?
CodePudding user response:
Removing the four zero-width characters present in the second JSON sample should resolve the error, either manually or by running the JSON sample through a regex to strip out the 0x200b
values before parsing it with Jackson.