A new serialization engine that provides serialization and deserialization services for complex graphs of objects, preserving references and allowing for polymorphism of trusted types, with a flexible and modular configuration. Works on .NET Standard 2.0.
The default services provide:
- Reflection-based constructor, property, and field services.
- Collection services for serializing
IEnumerable<T>
s and deserializingIList<T>
, arrays, and other collections withIEnumerable<T>
constructors. - Object initialization without a constructor, if none is available.
- Primitive type serializers for
string
,int
,uint
,long
,ulong
,float
,double
,bool
,DateTime
,Guid
, andVector2
, as well as the BassClefStudio.NET primitivesDateTimeZone
,DateTimeRange
, andColor
. IgnoreSerialize
attribute for ignoring properties and fields while serializing.- Output
IGraphWriter
implementation for JSON. - Dependency injection support with Autofac (optional) with methods like
RegisterGraphSerializer()
,RegisterDefaultGraphServices()
RegisterGraphService<T>()
, andRegisterGraphConfiguration()
.
The core GraphSerializer
also provides native support for circular references, generic types, trusted types (for polymorphism), and reference preservation through the use of IDs for objects and a full digraph framework for managing relationships between objects in the model.
builder.RegisterGraphSerializer();
builder.RegisterDefaultGraphServices();
builder.RegisterGraphConfiguration(
new CustomTypeConfiguration()
{
TrustedTypes = ...
});
builder.RegisterGraphService<MyCustomSerializer>();
...
ISerializationService service;
string json = service.Serialize(oldObject);
MyObject newObject = service.Deserialize<MyObject>(json);