My frontend implementer is running into a strange issue with a rather complex nested DTO.
Here is the json that he is passing through a jquery ajax call
{"Id":"507e7e5aa6305825c012c606","Name":"test fried chicken","Description":"why you no work","Servings":4,"Author":"unit test","Steps":[{"Instructions":"put chicken in egg","Ingredients":[{"PreparationId":"507e7e34a6305825c012c601","MeasureId":"kilogram","Quantity":2,"MeasureType":"weight"},{"PreparationId":"507e7e36a6305825c012c605","MeasureId":"gram","Quantity":100,"MeasureType":"weight"}]},{"Instructions":"put in flour and cook it up","Ingredients":[{"PreparationId":"507e7e35a6305825c012c603","MeasureId":"gram","Quantity":100,"MeasureType":"weight"}]}]}
That is going as a PUT to uri/recipes which then being converted on the request side to a default instance of the DTO (none of the information is actually being deserialized).
If I take the exact same Json from the request and run the C# code
var d = new ServiceStack.Text.JsonSerializer<RecipeDTO>();
var re = d.DeserializeFromString(theJson);
var client = new JsonServiceClient(uri);
client.Put<RecipeDTOResponse>("/recipes", re);
then it works. Any ideas why there is a difference?
After logging the IHttpRequest coming from both the webpage and the C# client, I noticed that ContentType for the jquery call was application/x-www-form-urlencoded while c# was application/json.
Changing it in the jquery call resolved the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With