vendredi 23 janvier 2015

Sample JSON by C# class definition

I am looking for a code or lib which can create JSON by C# class definition. For example if I have an action (MVC or Web API):



[HttpGet]
[Route("Hosts")]
public void GetHosts(VendorSettings[] vendors)


And my classes defined as:



public class VendorSettings
{
public string Vendor { get; set; }

public int Id { get; set; }

public StreamSettings Entitlements { get; set; }
}

public class StreamSettings
{
public string Host { get; set; }

public string Name { get; set; }
}


I want to see my documentation for this action as:



{
Route: "Hosts/GetHosts",
Parameters:
[
{
Name: "vendors",
Type: "VendorSettings[]"
/* I am looking for solution only for this part */
Example:
[
{
Vendor: "",
Id: 0,
Entitlements:
[
{
Host: "",
Name: ""
}
]
},
]
},
],
}


I can handle all routing stuff, so my question is only about creating sample JSON by class defenition. I cannot create an instance of VendorSettings and use standard JSON serializer because it could be abstract or it could have no parameterless constructor. It is not a big deal to write it from scratch, but if someone already made same task I would love to reuse this code. Motivation is help page for selfhosted Web API.


Any links will be appreciated.






Aucun commentaire:

Enregistrer un commentaire