I am facing one issue. The application is Kotlin +...
# getting-started
h
I am facing one issue. The application is Kotlin + Java. I am calling a Kotlin REST Resource passing the escaped backslash in the payload. but I am getting the below error:
Unable to Parse JSON.
Request Payload:
Copy code
{
  "eventTypeId": "USR-05 \" "
}
REST Controller
Copy code
@Produces(MediaType.APPLICATION_JSON)
@Path("/audit/api/1/events")
open class WriteAuditEventResource {
	
	@POST
    @Consumes(MediaType.APPLICATION_JSON)
    fun writeEvent(eventRequest: AuditEventRequest): Response {
        return Response.status(Response.Status.CREATED).build()
    }

}
Problem: 1. In HTTP Logs I can see that the escaped backslash is converted to double backslash (making the JSON invalid). Below are the logs:
Copy code
{
    "eventTypeId": "USR-05 \\" "
}
Copy code
[o.e.jetty.http.HttpParser     ] - parseNext s=CONTENT HeapByteBuffer@64870bee[p=273,l=308,c=8192,r=35]={POST /aud... 35\r\n\r\n<<<{\n    "eventTypeId": "USR-05 \\" "\n}>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00} 
[o.e.jetty.server.HttpChannel  ] - onContent HttpChannelOverHttp@f084976{s=HttpChannelState@4962b62c{s=HANDLING rs=BLOCKING os=OPEN is=IDLE awp=false se=false i=true al=1},r=1,c=false/false,a=HANDLING,uri=//localhost:8686/audit/api/1/events/,age=35} Content@2bcdd012{HeapByteBufferR@793bf03f[p=273,l=308,c=8192,r=35]={POST /aud... 35\r\n\r\n<<<{\n    "eventTypeId": "USR-05 \\" "\n}>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00}} 
[o.e.jetty.server.HttpInput    ] - HttpInputOverHTTP@3716942e[c=0,q=0,[0]=null,s=STREAM] addContent Content@2bcdd012{HeapByteBufferR@793bf03f[p=273,l=308,c=8192,r=35]={POST /aud... 35\r\n\r\n<<<{\n    "eventTypeId": "USR-05 \\" "\n}>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00}} 
[o.e.jetty.http.HttpParser     ] - CONTENT --> CONTENT_END 
[o.e.jetty.server.HttpChannel  ] - onContentComplete HttpChannelOverHttp@f084976{s=HttpChannelState@4962b62c{s=HANDLING rs=BLOCKING os=OPEN is=IDLE awp=false se=false i=true al=1},r=1,c=false/false,a=HANDLING,uri=//localhost:8686/audit/api/1/events/,age=36} 
[o.e.jetty.http.HttpParser     ] - CONTENT_END --> END
2. In Java Servlet Filter, if I extract the request payload from HttpServlet then I am getting below string as input:
Copy code
{
    "eventTypeId": "USR-05 " "
}
StackTrace:
Copy code
[.JsonProcessingExceptionMapper] - Unable to process JSON ! com.fasterxml.jackson.databind.JsonMappingException: Unexpected character ('"' (code 34)): was expecting comma to separate Object entries
!  at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 395] (through reference chain: com.anaplan.audit.write.api.request.AuditEventRequest["eventTypeId"])
! at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:402)
! at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:361)
! at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1826)
! at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:280)
! at com.fasterxml.jackson.module.afterburner.deser.SuperSonicBeanDeserializer.deserialize(SuperSonicBeanDeserializer.java:155)
! Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('"' (code 34)): was expecting comma to separate Object entries
!  at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 395]
! at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2418)
! at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:749)
! at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:673)
! at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextFieldName(UTF8StreamJsonParser.java:1061)
! at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap(MapDeserializer.java:608)
More Details:
Copy code
Kotlin Version: 1.3.0
JDK version: 1.8
jackson-module-kotlin: 2.8.9
Could you please help me with this, how can I process this request containing the escaped double quote?
r
Could it be that the problem is happening client, not server side? How is the request body being created on the client?
h
I have sent the request from Postman and also tried the CURL on terminal.
this is the curl:
Copy code
curl --location 'https://***.com/audit/*/events/' --header 'Content-Type: application/json' --data '{"eventTypeId":"Escape Double Quote \" "}'
r
OK, looks like it's not a client side problem then...
In my Jetty logs I see the same thing:
Copy code
DEBUG [2025-02-10 17:29:18,231] req= org.eclipse.jetty.http.HttpParser: parseNext s=CONTENT DirectByteBuffer@41793ff3[p=229,l=262,c=8192,r=33]={POST /__/...080\r\n\r\n<<<{\n  "eventTypeId": "USR-05 \\" "\n}>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00}
but it's still parsed fine by Jackson, so the double backslash seems to be an artefact of the Jetty logging rather than a sign of the problem.
What versions of Jetty, Jackson & Jersey are you using?
h
@Rob Elliot Here are the versions used in pom.xml
Copy code
jackson: 2.14.1
jackson-databind: 2.14.1
jackson-core: 2.14.1
jackson-annotations: 2.14.1
jackson-module-jsonSchema: 2.14.1
jackson-module-kotlin: 2.8.9

dropwizard-jetty: 2.1.10
jetty-server: 9.4.53.v20231009
jetty-servlets: 9.4.53.v20231009

dropwizard-jersey: 2.1.10
jersey-client: 2.26
jersey-media-multipart: 2.26
have you got any chance to dig into this?