Table of Contents

Class JsonSerializer

Namespace
NMF.Serialization.Json
Assembly
NMF.Serialization.Json.dll

Denotes a Json Serializer based on System.Text.Json

public class JsonSerializer : Serializer
Inheritance
JsonSerializer
Inherited Members

Constructors

JsonSerializer()

Creates a new model serializer

public JsonSerializer()

JsonSerializer(Serializer)

Creates a new serializer and copies settings and known types from the given serializer

public JsonSerializer(Serializer parent)

Parameters

parent Serializer

An XML serializer to copy settings and known type information from

JsonSerializer(Serializer, XmlSerializationSettings)

Creates a new serializer and copies settings and known types from the given serializer

public JsonSerializer(Serializer parent, XmlSerializationSettings settings)

Parameters

parent Serializer

An XML serializer to copy settings and known type information from

settings XmlSerializationSettings

The serialization settings

JsonSerializer(XmlSerializationSettings)

Creates a new model serializer

public JsonSerializer(XmlSerializationSettings settings)

Parameters

settings XmlSerializationSettings

The serialization settings

JsonSerializer(XmlSerializationSettings, IEnumerable<Type>)

Creates a new serializer and copies settings and known types from the given serializer

public JsonSerializer(XmlSerializationSettings settings, IEnumerable<Type> knownTypes)

Parameters

settings XmlSerializationSettings

The serialization settings

knownTypes IEnumerable<Type>

A collection of known types

Methods

CreateObject(ref Utf8JsonStreamReader, ref ITypeSerializationInfo)

Creates the output object for the given reader position

protected object CreateObject(ref Utf8JsonStreamReader reader, ref ITypeSerializationInfo info)

Parameters

reader Utf8JsonStreamReader

the JSON reader with the current position

info ITypeSerializationInfo

the type info

Returns

object

the created object

Deserialize(ref Utf8JsonStreamReader)

Deserializes the contents from the given reader

public object Deserialize(ref Utf8JsonStreamReader reader)

Parameters

reader Utf8JsonStreamReader

the JSON reader to read from

Returns

object

the object contained in the JSON format

Deserialize(ref Utf8JsonStreamReader, bool)

Deserializes the contents from the given reader

public object Deserialize(ref Utf8JsonStreamReader reader, bool fragment)

Parameters

reader Utf8JsonStreamReader

the JSON reader to read from

fragment bool

true, if the stream contains a fragment, otherwise false

Returns

object

the object contained in the JSON format

Initialize(ref Utf8JsonStreamReader, XmlSerializationContext, object, ITypeSerializationInfo)

Initializes the provided object given the reader position

protected void Initialize(ref Utf8JsonStreamReader reader, XmlSerializationContext context, object deserialized, ITypeSerializationInfo info)

Parameters

reader Utf8JsonStreamReader

the JSON reader

context XmlSerializationContext

the serialization context

deserialized object

the deserialized object that should be initialized

info ITypeSerializationInfo

the type information for the object

OverrideIdentifiedObject(object, Utf8JsonStreamReader, XmlSerializationContext)

Determines whether the already identified element should be overridden

protected virtual bool OverrideIdentifiedObject(object obj, Utf8JsonStreamReader reader, XmlSerializationContext context)

Parameters

obj object

The object that would be overridden

reader Utf8JsonStreamReader

The current reader position

context XmlSerializationContext

The serialization context

Returns

bool

true, if the element shall be overridden, otherwise false

Serialize(object, Utf8JsonWriter, IPropertySerializationInfo, XmlIdentificationMode, XmlSerializationContext, bool)

Serializes the given object

public virtual void Serialize(object obj, Utf8JsonWriter writer, IPropertySerializationInfo property, XmlIdentificationMode identificationMode, XmlSerializationContext context, bool shallow = false)

Parameters

obj object

The object to be serialized

writer Utf8JsonWriter

The Utf8JsonWriter to write the JSON-code on

property IPropertySerializationInfo

The property for which the object is serialized

identificationMode XmlIdentificationMode

A value indicating whether it is allowed to the serializer to use identifier

context XmlSerializationContext

The serialization context

shallow bool

true, if only attributes should be serialized, otherwise false

Remarks

If a converter is provided that is able to convert the object to string and convert the string back to this object, just the string-conversion is printed out

Serialize(object, Utf8JsonWriter, bool, bool)

Serializes the given object

public void Serialize(object source, Utf8JsonWriter target, bool shallow = false, bool fragment = false)

Parameters

source object

The object to be serialized

target Utf8JsonWriter

The Utf8JsonWriter to write the JSON-code on

shallow bool

true, if only attributes should be serialized, otherwise false

fragment bool

true, if the element should be serialized as fragment

WriteConstructorProperties(Utf8JsonWriter, object, ITypeSerializationInfo, XmlSerializationContext)

Writes the properties necessary for the constrctor call of this element

protected virtual void WriteConstructorProperties(Utf8JsonWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)

Parameters

writer Utf8JsonWriter

The JSON writer to write to

obj object

The element

info ITypeSerializationInfo

The serialization information of the objects type

context XmlSerializationContext

The serialization context

WriteIdentifiedObject(Utf8JsonWriter, object, XmlIdentificationMode, ITypeSerializationInfo, XmlSerializationContext)

Writes the provided identified object

protected virtual bool WriteIdentifiedObject(Utf8JsonWriter writer, object obj, XmlIdentificationMode identificationMode, ITypeSerializationInfo info, XmlSerializationContext context)

Parameters

writer Utf8JsonWriter

The Json writer to write to

obj object

The element

identificationMode XmlIdentificationMode

The identification mode for the current object

info ITypeSerializationInfo

The serialization information of the objects type

context XmlSerializationContext

The serialization context

Returns

bool

true, if the object could be written as identified object, otherwise false

WriteProperties(Utf8JsonWriter, object, ITypeSerializationInfo, XmlSerializationContext, bool)

Writes the properties of the given object

protected virtual void WriteProperties(Utf8JsonWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context, bool shallow)

Parameters

writer Utf8JsonWriter

The Json writer to write to

obj object

The element

info ITypeSerializationInfo

The serialization information of the objects type

context XmlSerializationContext

The serialization context

shallow bool

true, if only attributes should be serialized, otherwise false