Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`

0

I am trying to send back a result from a Lambda to my LexV2 bot, everything seems to be routed correctly until Lex displays the result in the test chat : Invalid Lambda Response: "Received invalid response from Lambda: Cannot deserialize value of type java.lang.String from Object value (token JsonToken.START_OBJECT) at [Source: (String)"{"sessionState": {"activeContexts": [{"name":..." I don't get where is the issue since my lambda returns the appropriate format for the response :

Enter image description here

What am I missing here ?

Florian
asked a year ago3750 views
2 Answers
0
Accepted Answer

Ok, I initially did not think it was a format issue at first but it is. The response is in the correct format that Lex can receive except my 'message' portion which was in the incorrect format.

Florian
answered a year ago
profile picture
EXPERT
reviewed a year ago
0

Can you try to use JSON.dumps (if using python) or similar to what JSON.stringify does for Javascript? Wrap the whole response object.

profile picture
EXPERT
answered a year ago
  • I tried that, this is what I get on the lex chat side : Invalid Lambda Response: Received invalid response from Lambda: Cannot construct instance of IntentResponse (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{"sessionState": {"activeContexts":...<rest of the lambda response>.

    here is where I get the response right before I send it back to lex : print(f"Response: {intent_name} -> Lambda: {fn_name} : {payload}") the resulting log : Response: ListProducts -> Lambda: LexListProducts : { "sessionState": { "activeContexts": [ { "name": "intentContext", "contextAttributes": {}, "timeToLive": { "timeToLiveInSeconds": 600, "turnsToLive": 1 } } ], "sessionAttributes": {}, "dialogAction": { "type": "Close" }, "intent": { "confirmationState": "None", "name": "ListProducts", "slots": {}, "state": "InProgress" } }, "messages": [ { "contentType": "PlainText", "content": { "contentType": "PlainText", "content": "On vend des pommes" } } ] }

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions