2

In asp.net web api core 1.0 (I hope same as in asp.net web api 2.0), while serializing an object which is inherited from DynamicObject ignores the class's own declared properties.

public class Demo : DynamicObject
{
 // This property is ignore in api response
 public int Prop1 {get; set;}
}

Actual Json:

 {"DynamicProp1": "abc", "DynamicProp2" : 123 ... so on}

Expected Json:

{"Prop1": 123, "DynamicProp1": "abc", "DynamicProp2" : 123 ... so on}

Any suggestion?

2
  • Can you put the return object? I mean, if you initialize your variable as DynamicObject then it acts as it is expected. Commented Sep 5, 2016 at 11:11
  • I just got a solution. Thanks. Posting the solution as answer myself Commented Sep 5, 2016 at 11:51

1 Answer 1

1

Thanks, I got a solution

[DataContract]
public class Demo : DynamicObject
{
 // This property is ignore in api response
 [DataMember]   OR [JsonProperty]
 public int Prop1 {get; set;}
}

Original question.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.