Skip to content
Rpgmaker edited this page May 18, 2021 · 11 revisions

Supported .Net Version:

3.5 - 4.x Net Framework
    .Net Core (.Net Standard 1.6+)
    .NET 5

Supported Types:

Tuple
Expando (4.x Net Framework)
Any IDictionary implementing IEnumerable<KeyValuePair<K,V>
	- E.x ConcurrentDictionary, HashSet, Dictionary, SortedDictionary, and e.t.c
Dictionary<String, Object>
	- Value(Object) supported Dictionary<string, object>, IList, Primitive Types, and Enums	
Primitive Type (Including byte[], Guid, Timespan, DateTime, e.t.c)
Struct and Class (Only public properties and fields are supported)
    Automatic quote detection
  Support renaming property/field names used for both serialization and deserialization using [NetJSONProperty] attribute
  Serialization of Type class

Supported Options:

NetJSON.DateFormat = Default | ISO | EpochTime (default: Default)
	- Default: Generate the standard json date representation "\Date(value)"
	- ISO: Generate iso format of date using ISO 8601 e.x 2015-07-29T14:59:08Z
	- EpochTime: Generate a unix representation of the date

    NetJSON.DateStringFormat = default: Null
             - This allows customization of date formatting and ignore other formatting option when specified.
 
    NetJSON.TimeZoneFormat = Unspecified | Utc | Local (default: Unspecified)
            - This allows you to include the timezone information as part of serialization

    NetJSON.ShareAssembly = true | false (default: true)
            - This option allows NetJSON to place all types needed for serialization/deserialization in other to avoid the cost of generating multiple assemblies within the runtime

NetJSON.UseEnumString = true | false (default: false)
	- It will convert enum to their string name representation rather than using the value.
	
NetJSON.IncludeFields = true | false (default: false)
	- Include fields in serialization if value is true
	
NetJSON.SkipDefaultValue = true | false (default: true)
	- Ignore serialization of value of primitive type and reference type therefore reducing the generated payload
	- E.x. Nullable<int> will be serialize with the value of 0 if it is set. But if it is not set then it will never be serialized
	
NetJSON.CaseSensitive = true | false (default: true)
	- Allow serialization of mix case for properties and fields if enabled
	
NetJSON.GenerateAssembly = true | false (default: false)
	- Allow outputting the generated assembly used for serializing and deserializing the class
	- Naming convention: <NameOfType>Class. E.x. Foo will become FooClass

    NetJSON.QuoteType = Single | Double (default: Double)
            - Determine whether to serialize json property/field using single or double quotes

    NetJSON.UseStringOptimization = true | false (default: true)
            - Allow NetJSON to automatically try to skip noise in json that requires reading character by character value
    NetJSONSettings.Format = Default | Prettify (default: Default)
            - Allow NetJSON to format the generated json in a readable format when option is Prettify

    NetJSON.SerializeAs
            - Allow specifying a custom delegate to determine the names to use for the field/property during serialization

    NetJSON.CanSerialize
            - Allow specifying a custom delegate to implement custom attribute and other features to allow additional functionality such as Ignoring fields/properties, and etc

Supported Methods:

string Serialize<T>(T value)

void Serialize<T>(T value, TextWriter writer)
          - Write the result of serializing T into the specific writer object

string Serialize(Type type, object value)

    string SerializeObject(object value, NetJSONSettings settings)
           - Allow serialization using underlying object type of specified value

T Deserialize<T>(string value)

T Deserialize<T>(TextReader reader)
          - Reads content of reader and deserialize into T object 

object Deserialize(Type type, string value)

object DeserializeObject(string json)
	- This method allows you to generate a recursive Dictionary<string, object> representation of the json string
	
GenerateTypesInto(string asmName, params Type[] types)
	- This method allows you to specify a list of types you would like to serialize and deserialize  and output an assembly which will contain the code that can be reference for precompile serialization code
	- Using this method allow you to avoid the initial cost of generating the classes needed to serialize your objects

    RegisterTypeSerializer<T>(Func<T, string> serializeFunc)
             - This method allows you to register method that can be used for custom serialization of primitive type use for object type when dealing with scenario such as serializing Dictionary<string, object> or any specific object type
Clone this wiki locally