0

I'm currently working an a problem that must be solved many times before. But I could not find a solution that I would like to implement.

There is a page where the users can configure the application. This configurations are having different datatypes. Most of them are just native (string, bool, int, ...) but some are having complexe types as value. So there is a class representing the configurations as they are send to the browser as JSON:

public class ConfigurationModel
{
   public string Key { get; set; }
   public object Value { get; set; }
}

At the browser this values are modified and can be saved. So the same object are send back to the server. For any reason the values of the configurations with a complexe type are not deserialized correctly but given as JObject.

Is there a common way to handle the deserialization without creating custom extensions to json.net? If not, is there a way to do this without having to access the properties with "strings"?

EDIT: Thank you for the duplicated hint but it is not realy the same question. I want the WebAPI to convert the objects correctly without having to convert the JObject manualy!

EDIT#2: All the suggested topics are somehow using the JObjects and convert them manualy to the correct type. So there has to be a part of the code where the correct type has to be know. For Example by using

JObject.ToObject<T>();

What I was trying to achieve is to have the correct types already in the list without this conversion needed.

Dominik Kirschenhofer
  • 1,205
  • 1
  • 13
  • 27

0 Answers0