This repository has been archived by the owner. It is now read-only.

Deserialization error #1

Closed
szymczakk opened this Issue Nov 13, 2017 · 1 comment

Comments

1 participant
@szymczakk
Owner

szymczakk commented Nov 13, 2017

This is error that is generated:

{ "errorType": "JsonSerializationException", "errorMessage": "Error converting value "{"BusCount":0,"NextBusDates":null}" to type 'mpkLikeAlexa.BusResponseModel'. Path 'body', line 1, position 80.", "stackTrace": [ "at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)", "at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)", "at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)", "at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)", "at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)", "at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)", "at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)", "at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)", "at mpkLikeAlexa.Function.HandleBussTimeIntent(IntentRequest intentRequest, ILambdaContext context)", "at mpkLikeAlexa.Function.FunctionHandler(SkillRequest input, ILambdaContext context)", "at lambda_method(Closure , Stream , Stream , ContextInfo )" ], "cause": { "errorType": "ArgumentException", "errorMessage": "Could not cast or convert from System.String to mpkLikeAlexa.BusResponseModel.", "stackTrace": [ "at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)", "at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)", "at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)" ] } }

when I try to deserialize such JSON

{"statusCode":200,"headers":null,"body":"{\"BusCount\":0,\"NextBusDates\":null}","isBase64Encoded":false}

or this

{"statusCode":200,"headers":null,"body":"{\"BusCount\":2,\"NextBusDates\":[\"2017-11-13T22:20:29.631227+00:00\",\"2017-11-13T22:08:29.63163+00:00\"]}","isBase64Encoded":false}

taken from https://3yrnvbq3nc.execute-api.eu-central-1.amazonaws.com/dev

Most relevant code is in mpkLikeAlexa/Function.cs and here

@szymczakk

This comment has been minimized.

Show comment
Hide comment
@szymczakk

szymczakk Nov 24, 2017

Owner

fixed. object comming from API Gateway contain body as a string which required 2 deserialization. 1st to deserialize the response and then one to deserialize the body object.

Owner

szymczakk commented Nov 24, 2017

fixed. object comming from API Gateway contain body as a string which required 2 deserialization. 1st to deserialize the response and then one to deserialize the body object.

@szymczakk szymczakk closed this Nov 24, 2017

@szymczakk szymczakk added the bug label Nov 24, 2017

@szymczakk szymczakk self-assigned this Nov 24, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.