Smoothing a JSON Nested Object in JSON.NET

I have a simple JSON:

{
    "id": 123,
    "name": "BaseName",
    "variation": { "name": "VariationName" }
}

Is there an easy way to map it to JSON.NET deserialization:

class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string VariationName { get; set; }
}

Maybe I can do this with a custom converter, but I was hoping it would be easier by annotating a class with attributes that would give instructions for deserializing the change object using only one property.

+4
source share
1 answer

You can configure the class for variationand make the VariationNameproperty get-only

class Product
{
    public int Id { get; set; }
    public string Name { get; set; }

    public Variation variation { get; set; }
    public string VariationName { get { return variation.VariationName; } }
}

class variation 
{
    public string name { get; set; }
}
+2
source

All Articles