0

I'm developing my own JSON-to-POCO framework. The way I'm doing it is, that I created the class of a Json-schema that looks like this:

public class JsonSchema  
{
    public string type { get; set; }
    public string title { get; set; }
    public string description { get; set; }
    public Dictionary<string, JsonSchema> properties { get; set; }
    public JsonSchema items { get; set; }
    public string id { get; set; }
    public List<string> required { get; set; }
    public bool ispartial = true; 
}

and deserializing the schema to have my object(s) so I can work with it perfectly.

Everything is working fine for now, I'm getting my generated C#-file. But only if I don't add $refs to my json. (Since it's much less code to add a reference in json instead of copy-paste the classes I want to support them)

What I need to do is, adding the $ref to my class. Problem here is, I cannot add an attribute like

public string $ref { get; set; }

to my code.

Any idea what I could do?

The problem was also, that you cannot deserialize $id and $ref with default settings. This was solved by reading this nice post here: JsonConvert.DeserializeObject<> (string) returns null value for $id property

Community
  • 1
  • 1
Matthias Burger
  • 5,549
  • 7
  • 49
  • 94
  • 1
    If you are using Json.net you can add a [JsonProperty("$ref")] and rename the actual property to something like reference. – riteshmeher Jun 06 '16 at 18:37
  • @riteshmeher it's working fine with $schema when I tested it. Not with my $ref. So this has to be another part of my code where the mistake is. Post it as an answere so I can mark it as correct ;) – Matthias Burger Jun 06 '16 at 19:07

1 Answers1

2

You may add [JsonProperty] attribute to the property you want to change the name.

[JsonProperty("$ref")]
public string reference { get; set; }
riteshmeher
  • 854
  • 8
  • 16