Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Unable to deserialize to Newtonsoft.Json.Linq.JToken #64

Open
gimmi opened this issue Jan 11, 2017 · 2 comments
Open

Unable to deserialize to Newtonsoft.Json.Linq.JToken #64

gimmi opened this issue Jan 11, 2017 · 2 comments

Comments

@gimmi
Copy link

gimmi commented Jan 11, 2017

Hi,

given the following dto

public class Dto
{
    public Guid Id { get; set; }
    public string Name { get; set; }
}

this code work as expected, receiving application/json body and responding with application/json

Post["/echo"] = arg => this.Bind<Dto>();

the same request return an empty json ({}) with this implementation

Post["/echo"] = arg => this.Bind<JObject>();

What's wrong with this endpoint? Isn't deserialization to JToken working?

@gimmi
Copy link
Author

gimmi commented Jan 11, 2017

Seems that JObject deserialization work as expected for inner field like these:

public class Dto
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public JObject Props { get; set; }
}

@techaimail
Copy link

Currently the exception is the following:
Message of InvalidDataContractException: Type 'Newtonsoft.Json.Linq.JToken' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants