2

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?

1 Answer 1

3

0x200b is the Unicode value for a zero-width space, which it seems like the Jackson JSON parser is not able to handle. Zero-width spaces aren't usually visible in most editors by default, which results in confusing situations like the one you've encountered.

Your text or code editor might have a setting to show hidden characters; I pasted both of your snippets into Sublime Text, and it showed me the hidden characters that are causing the problem:

screenshot of the code in the previous post, showing multiple zero-width characters in the second JSON sample

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! I would've wasted hours solving it by myself. I wonder if there's any possibility to make Jackson handle zero-width space characters.
Which text editor were you using?
The text editor in the above screenshot is Sublime Text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.