Nested Schema translation to c# code


#1

I have a schema with a nested element in it to represent a map with multiple locations:

schemaName:
Map
fields:
Zoom [string]
Locations [nested]

  • Location [string]

However for the life of me I cannot get it mapped into a c# object:

for example, this doesn’t work:

[KeepCasingAttribute]
public class MapData
{
    [JsonConverter(typeof(InvariantConverter))]
    public int Zoom { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public List<string> Locations { get; set; }
}

nor does:

[KeepCasingAttribute]
public class LocationData
{
    [JsonConverter(typeof(InvariantConverter))]
    public List<string> Location { get; set; }
}

[KeepCasingAttribute]
public class MapData
{
    [JsonConverter(typeof(InvariantConverter))]
    public int Zoom { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public LocationData Locations { get; set; }
}

Any clues as to what I’m doing wrong ?

Thanks


#2

It is easier when you have a look to the schema

The result is

public class Location
{
    public string Location { get; set; }
}

[KeepCasingAttribute]
public class MapData
{
    [JsonConverter(typeof(InvariantConverter))]
    public int Zoom { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public Location[] Locations { get; set; }
}