Programming

Serializing JSON Values Without Quotes

Serializing JSON values without quotes I have a package called ChartJSCore which generates the required JavaScript for creating Chart.js charts in a web application. For the most part the JS for this is essentially JSON so this works by serializing chart objects using Newtonsoft which automatically quotes both the object Read more…

By Shinigami, ago
Programming

Enum JSON Converter

Enum JSON converter. In addition to the SingleOrArrayEnumConverter mentioned previously I’ve also created a version to translate enums to/from JSON using the name of the enum rather than it’s value as is the default. class EnumConverter<T> : JsonConverter { public override bool CanConvert(Type objectType) { return (objectType == typeof(T)); } Read more…

By Shinigami, ago
Programming

Single or Array Enum JSON Converter

Single or array enum JSON converter. In addition to the SingleOrArrayConverter mentioned previously I’ve also created a version to translate enums to/from JSON using the name of the enum rather than it’s value as is the default. public class SingleOrArrayEnumConverter<T> : JsonConverter { public override bool CanConvert(Type objectType) { return Read more…

By Shinigami, ago
Programming

Single or Array JSON Converter

Single or array JSON converter. Often APIs will have actions where one of the parameters can be either a single object or an array of objects, in order to correctly serialize objects to JSON which can be accepted by the API a custom JsonConverter is needed. This code is borrowed Read more…

By Shinigami, ago