Cannot deserialize instance of `java.util.LinkedHashMap` out of START_ARRAY token

2,789 views
Skip to first unread message

tech.abd...@gmail.com

unread,
Dec 3, 2018, 10:35:51 AM12/3/18
to vert.x
I am facing an issue while getting accessing the body of my http put request in Vert.x. The exception which I am getting is com.fasterxml.jackson.databind.exc.MismatchedInputException. The same code works when I try it with postman. I am not able to figure it out what making it different when I request from my application. 

I am following these steps, 

1) I have registered the handler. 
 router.route("/record").handler(BodyHandler.create());

2) then I try to get the body of my put request 
JsonObject body = routingContext.getBodyAsJson(); 

This works when I call from postman but starts complaining when I try from my application. 

My JSon object is a bit complex but it does not work if even I shorten the Json object. 

My Json in body is
{
    "ani": "23452",
    "cdtd": 1,
    "fields": [
        [
            {
                "id": 1,
                "name": "firstname",
                "type": "text",
                "text": "First Name",
                "values": null,
                "agentid": null,
                "agentname": null,
                "peripheralid": null,
                "maxlength": 20,
                "columnright": false,
                "value": "adsf",
                "updateincallvariable": "adf"
            },
            {
                "id": 2,
                "name": "lastname",
                "type": "text",
                "text": "Last Name",
                "values": null,
                "agentid": null,
                "agentname": null,
                "peripheralid": null,
                "maxlength": 20,
                "columnright": false,
                "value": "asdfas",
                "updateincallvariable": "asdfa"
            }
        ],
        [
            {
                "id": 1,
                "name": "email",
                "type": "text",
                "text": "First Name",
                "values": null,
                "agentid": null,
                "agentname": null,
                "peripheralid": null,
                "maxlength": 20,
                "columnright": false,
                "value": "adsf",
                "updateincallvariable": "adf"
            },
            {
                "id": 2,
                "name": "phone",
                "type": "text",
                "text": "Last Name",
                "values": null,
                "agentid": null,
                "agentname": null,
                "peripheralid": null,
                "maxlength": 20,
                "columnright": false,
                "value": "asdfas",
                "updateincallvariable": "asdfa"
            }
        ]
    ]
}

This does not work even if I shorten my Json

{
"ani": "+4962518622644",
"cdtd": 1,
"fields": "Nothing"
}

here is the full stack trace of exception, 

Dez 03, 2018 4:13:46 PM io.vertx.ext.web.impl.RoutingContextImplBase
SEVERE: Unexpected exception in route
io.vertx.core.json.DecodeException: Failed to decode:Cannot deserialize instance of `java.util.LinkedHashMap` out of START_ARRAY token
 at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 1]
at io.vertx.core.json.Json.decodeValue(Json.java:168)
at io.vertx.core.json.JsonObject.fromBuffer(JsonObject.java:952)
at io.vertx.core.json.JsonObject.<init>(JsonObject.java:72)
at io.vertx.ext.web.impl.RoutingContextImpl.getBodyAsJson(RoutingContextImpl.java:257)
at io.vertx.reactivex.ext.web.RoutingContext.getBodyAsJson(RoutingContext.java:316)
at com.buchersuter.customerdetails.verticles.AgentVerticle.updateRecord(AgentVerticle.java:124)
at io.vertx.reactivex.ext.web.Route$1.handle(Route.java:155)
at io.vertx.reactivex.ext.web.Route$1.handle(Route.java:153)
at io.vertx.ext.web.impl.RouteImpl.handleContext(RouteImpl.java:225)
at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:85)
at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:133)
at io.vertx.reactivex.ext.web.RoutingContext.next(RoutingContext.java:128)
at com.buchersuter.customerdetails.verticles.AgentVerticle.checkSession(AgentVerticle.java:77)
at io.vertx.reactivex.ext.web.Route$1.handle(Route.java:155)
at io.vertx.reactivex.ext.web.Route$1.handle(Route.java:153)
at io.vertx.ext.web.impl.RouteImpl.handleContext(RouteImpl.java:225)
at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:120)
at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:133)
at io.vertx.ext.web.handler.impl.BodyHandlerImpl$BHandler.doEnd(BodyHandlerImpl.java:231)
at io.vertx.ext.web.handler.impl.BodyHandlerImpl$BHandler.end(BodyHandlerImpl.java:211)
at io.vertx.ext.web.handler.impl.BodyHandlerImpl.lambda$handle$0(BodyHandlerImpl.java:74)
at io.vertx.core.http.impl.HttpServerRequestImpl.handleEnd(HttpServerRequestImpl.java:417)
at io.vertx.core.http.impl.Http1xServerConnection.handleEnd(Http1xServerConnection.java:482)
at io.vertx.core.http.impl.Http1xServerConnection.handleContent(Http1xServerConnection.java:477)
at io.vertx.core.http.impl.Http1xServerConnection.processMessage(Http1xServerConnection.java:458)
at io.vertx.core.http.impl.Http1xServerConnection.handleMessage(Http1xServerConnection.java:144)
at io.vertx.core.http.impl.HttpServerImpl$ServerHandlerWithWebSockets.handleMessage(HttpServerImpl.java:728)
at io.vertx.core.http.impl.HttpServerImpl$ServerHandlerWithWebSockets.handleMessage(HttpServerImpl.java:619)
at io.vertx.core.net.impl.VertxHandler.lambda$channelRead$1(VertxHandler.java:146)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:337)
at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:195)
at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:144)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:141)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.LinkedHashMap` out of START_ARRAY token
 at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 1]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1342)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1138)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1092)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromEmpty(StdDeserializer.java:599)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:360)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:29)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3070)
at io.vertx.core.json.Json.decodeValue(Json.java:166)
... 51 more


Any suggestion to troubleshoot this. 

Julien Viet

unread,
Dec 3, 2018, 11:56:04 AM12/3/18
to ve...@googlegroups.com
have you checked that the body is valid json ?

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/0e978941-4586-4cc3-a420-c529f3da87c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tech.abd...@gmail.com

unread,
Dec 4, 2018, 4:10:11 AM12/4/18
to vert.x
Can you please help a bit how I would know my Json in body is a valid Json. I tried reducing the complexity in my shorten Json but still this does not work. My Json body after reducing is; 

 {
"ani": "+23234535",
"cdtd": 1,
"fields": "Nothing"
}

Jez P

unread,
Dec 4, 2018, 4:44:15 AM12/4/18
to vert.x
If it works correctly in postman then I think in some way your application is sending something different to postman. Can I suggest logging the body before calling getbodyasjson and comparing the two calls? I do not believe the body is the same in both cases. 

tech.abd...@gmail.com

unread,
Dec 4, 2018, 8:33:14 AM12/4/18
to vert.x
You are right. At application side I was passing body in variable as it is. I was able to fix it after wrapping by request body with stringify. 

JSON.stringify(body);

Thanks for the hint. 
Reply all
Reply to author
Forward
0 new messages