Superfluous "Stringification" and javax.json.stream.JsonParsingException 📎
"javax.json.stream.JsonParsingException: JsonParser#getObject() or JsonParser#getObjectStream() is valid only for START_OBJECT parser state. But current parser state is VALUE_STRING"
...can be caused by a superfluous "stringification" of regular JavaScript strings, like e.g. JSON.stringify(aString)
The JSON-P parser expects: {"hey":"duke"}
but gets: "{\"hey\":\"duke\"}"
To fix the problem, remove JSON.stringify(aString);
and send the string directly to the MicroProfile server:
const payload = "{"hey":"duke"}";
const response = await fetch("http://localhost:8080/imports", {
method: 'POST',
body: payload,
headers: {
'Content-type':'application/json'
}
});