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
SerializerAn 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
SerializerAn XML serializer to copy settings and known type information from
settings
XmlSerializationSettingsThe serialization settings
JsonSerializer(XmlSerializationSettings)
Creates a new model serializer
public JsonSerializer(XmlSerializationSettings settings)
Parameters
settings
XmlSerializationSettingsThe 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
XmlSerializationSettingsThe 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
Utf8JsonStreamReaderthe JSON reader with the current position
info
ITypeSerializationInfothe 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
Utf8JsonStreamReaderthe 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
Utf8JsonStreamReaderthe JSON reader to read from
fragment
booltrue, 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
Utf8JsonStreamReaderthe JSON reader
context
XmlSerializationContextthe serialization context
deserialized
objectthe deserialized object that should be initialized
info
ITypeSerializationInfothe 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
objectThe object that would be overridden
reader
Utf8JsonStreamReaderThe current reader position
context
XmlSerializationContextThe 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
objectThe object to be serialized
writer
Utf8JsonWriterThe Utf8JsonWriter to write the JSON-code on
property
IPropertySerializationInfoThe property for which the object is serialized
identificationMode
XmlIdentificationModeA value indicating whether it is allowed to the serializer to use identifier
context
XmlSerializationContextThe serialization context
shallow
booltrue, 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
objectThe object to be serialized
target
Utf8JsonWriterThe Utf8JsonWriter to write the JSON-code on
shallow
booltrue, if only attributes should be serialized, otherwise false
fragment
booltrue, 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
Utf8JsonWriterThe JSON writer to write to
obj
objectThe element
info
ITypeSerializationInfoThe serialization information of the objects type
context
XmlSerializationContextThe 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
Utf8JsonWriterThe Json writer to write to
obj
objectThe element
identificationMode
XmlIdentificationModeThe identification mode for the current object
info
ITypeSerializationInfoThe serialization information of the objects type
context
XmlSerializationContextThe 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
Utf8JsonWriterThe Json writer to write to
obj
objectThe element
info
ITypeSerializationInfoThe serialization information of the objects type
context
XmlSerializationContextThe serialization context
shallow
booltrue, if only attributes should be serialized, otherwise false