#json #jackson #fetch #fetch-api #jackson-databind
Вопрос:
Я получаю эту ошибку (внутренний сервер status 500).
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'justification': was expecting ('true', 'false' or 'null')
at [Source: (org.apache.catalina.connector.CoyoteReader); line: 1, column: 14]
com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1798)
com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:673)
com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2835)
com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1889)
com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:747)
com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4129)
com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3988)
com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3037)
dev.knapp.controllers.ReimbursementController.process(ReimbursementController.java:97)
dev.knapp.servlets.FrontControllerServlet.process(FrontControllerServlet.java:54)
dev.knapp.servlets.FrontControllerServlet.doPost(FrontControllerServlet.java:69)
javax.servlet.http.HttpServlet.service(HttpServlet.java:681)
org.apache.catalina.servlets.DefaultServlet.service(DefaultServlet.java:499)
javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
org.apache.catalina.filters.CorsFilter.handleNonCORS(CorsFilter.java:357)
org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:176)
Это происходит из-за этого вызова функции (Java).
Reimbursement r = om.readValue(request.getReader(), Reimbursement.class);
Вот моя асинхронная (JavaScript) функция отправки запроса.
let url = "http://localhost:8080/Project1/newrequest";
let request = {
userId: getCook("user_id"), //get from cookie
eventId: rrEvent, //should be event id//myEvent.event_id, //get id from event name (rrEvent)
isUrgent: true, //check date of event, compare to current date, if less than 2 weeks set true
status: "Needs direct supervisor approval",
justification: document.getElementById('justification').value,
projectedReimbursement: myEvent.cost,//get from event
amountReimbursed: 0,
isOverAvailable: false,//compare to user's available funds
isOverJustification: "N/A",
gradeReceived:"N/A",
workTimeMissed: document.getElementById('missedworktime').value
}
let res = await fetch(url, {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(request),
credentials: "include"
});
let resJson = await res.json()
.then(res => {
console.log(res);
})
.catch(error => {
console.log(error);
})
Мы высоко ценим любую помощь или понимание.