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
parentSerializerAn 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
parentSerializerAn XML serializer to copy settings and known type information from
settingsXmlSerializationSettingsThe serialization settings
JsonSerializer(XmlSerializationSettings)
Creates a new model serializer
public JsonSerializer(XmlSerializationSettings settings)
Parameters
settingsXmlSerializationSettingsThe 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
settingsXmlSerializationSettingsThe serialization settings
knownTypesIEnumerable<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
readerUtf8JsonStreamReaderthe JSON reader with the current position
infoITypeSerializationInfothe type info
Returns
- object
the created object
Deserialize(ref Utf8JsonStreamReader)
Deserializes the contents from the given reader
public object Deserialize(ref Utf8JsonStreamReader reader)
Parameters
readerUtf8JsonStreamReaderthe 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
readerUtf8JsonStreamReaderthe JSON reader to read from
fragmentbooltrue, 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
readerUtf8JsonStreamReaderthe JSON reader
contextXmlSerializationContextthe serialization context
deserializedobjectthe deserialized object that should be initialized
infoITypeSerializationInfothe 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
objobjectThe object that would be overridden
readerUtf8JsonStreamReaderThe current reader position
contextXmlSerializationContextThe 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
objobjectThe object to be serialized
writerUtf8JsonWriterThe Utf8JsonWriter to write the JSON-code on
propertyIPropertySerializationInfoThe property for which the object is serialized
identificationModeXmlIdentificationModeA value indicating whether it is allowed to the serializer to use identifier
contextXmlSerializationContextThe serialization context
shallowbooltrue, 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
sourceobjectThe object to be serialized
targetUtf8JsonWriterThe Utf8JsonWriter to write the JSON-code on
shallowbooltrue, if only attributes should be serialized, otherwise false
fragmentbooltrue, 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
writerUtf8JsonWriterThe JSON writer to write to
objobjectThe element
infoITypeSerializationInfoThe serialization information of the objects type
contextXmlSerializationContextThe 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
writerUtf8JsonWriterThe Json writer to write to
objobjectThe element
identificationModeXmlIdentificationModeThe identification mode for the current object
infoITypeSerializationInfoThe serialization information of the objects type
contextXmlSerializationContextThe 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
writerUtf8JsonWriterThe Json writer to write to
objobjectThe element
infoITypeSerializationInfoThe serialization information of the objects type
contextXmlSerializationContextThe serialization context
shallowbooltrue, if only attributes should be serialized, otherwise false