Wanzyee Studio
PartialConverter< T >abstract

Custom base Newtonsoft.Json.JsonConverter to filter serialized properties. More...

Inherits JsonConverter.

Public Member Functions

override bool CanConvert (Type objectType)
 Determine if the object type is T. More...
 
override object ReadJson (JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 Read the specified properties to the object. More...
 
override void WriteJson (JsonWriter writer, object value, JsonSerializer serializer)
 Write the specified properties of the object. More...
 

Protected Member Functions

abstract string[] GetPropertyNames ()
 Get the property names to serialize, only used once when initializing. More...
 
virtual T CreateInstance ()
 Create the instance for ReadJson() to populate. More...
 

Detailed Description

Custom base Newtonsoft.Json.JsonConverter to filter serialized properties.

Useful for Unity or 3rd party classes, since we can't insert any Newtonsoft.Json.JsonIgnoreAttribute. By the way, this works by reflection to access properties. Please make sure your property not to be stripped by Unity.

It's very easy to make a custom converter, just inherit and override GetPropertyNames() as the filter:

public class SomeConverter : PartialConverter<SomeClass>{
protected override string[] GetPropertyNames(){
return new []{"someField", "someProperty", "etc"};
}
}
Template Parameters
TThe value type.

Member Function Documentation

abstract string [] GetPropertyNames ( )
protectedpure virtual

Get the property names to serialize, only used once when initializing.

Returns
The property names.

Implemented in BoundsConverter, Matrix4x4Converter, ColorConverter, QuaternionConverter, RectConverter, RectOffsetConverter, Vector2Converter, Vector3Converter, and Vector4Converter.

virtual T CreateInstance ( )
protectedvirtual

Create the instance for ReadJson() to populate.

Returns
The instance.
override bool CanConvert ( Type  objectType)

Determine if the object type is T.

Parameters
objectTypeType of the object.
Returns
true if this can convert the specified type; otherwise, false.
override object ReadJson ( JsonReader  reader,
Type  objectType,
object  existingValue,
JsonSerializer  serializer 
)

Read the specified properties to the object.

Parameters
readerThe Newtonsoft.Json.JsonReader to read from.
objectTypeType of the object.
existingValueThe existing value of object being read.
serializerThe calling serializer.
Returns
The object value.
override void WriteJson ( JsonWriter  writer,
object  value,
JsonSerializer  serializer 
)

Write the specified properties of the object.

Parameters
writerThe Newtonsoft.Json.JsonWriter to write to.
valueThe value.
serializerThe calling serializer.