Class JsonStructureSerializer
- Namespace
- NanoByte.StructureEditor
- Assembly
- NanoByte.StructureEditor.dll
Serializes nodes as JSON using JsonSerializer.
public class JsonStructureSerializer : IStructureSerializer
- Inheritance
-
objectJsonStructureSerializer
- Implements
Constructors
JsonStructureSerializer()
Creates a serializer with DefaultOptions.
public JsonStructureSerializer()
JsonStructureSerializer(JsonSerializerOptions)
Serializes nodes as JSON using JsonSerializer.
public JsonStructureSerializer(JsonSerializerOptions options)
Parameters
optionsJsonSerializerOptionsOptions for the serializer. Use DefaultOptions as a starting point for customization.
Properties
DefaultOptions
The default options for the serializer: indented output without unnecessary escaping and populating existing (e.g., get-only) collections and objects instead of replacing them.
public static JsonSerializerOptions DefaultOptions { get; }
Property Value
FormatName
The name of the format (e.g., XML or JSON). Used to determine syntax highlighting.
public string FormatName { get; }
Property Value
Instance
A shared instance of the serializer using DefaultOptions.
public static JsonStructureSerializer Instance { get; }
Property Value
Methods
Deserialize<T>(string)
Deserializes an object from a string.
public T Deserialize<T>(string text) where T : class
Parameters
textstringThe serialized representation of the object.
Returns
- T
Type Parameters
TThe type of object to deserialize.
Exceptions
- Exception
The
textis not a valid serialized representation ofT.
Serialize<T>(T)
Serializes an object to a string.
public string Serialize<T>(T value) where T : class
Parameters
valueTThe object to serialize.
Returns
Type Parameters
TThe type to serialize the object as.
TryGetErrorLocation(Exception, out int, out int, out string)
Extracts the location of an error from an exception thrown by Deserialize<T>(string).
public bool TryGetErrorLocation(Exception exception, out int line, out int column, out string message)
Parameters
exceptionExceptionThe exception thrown by Deserialize<T>(string).
lineintThe 1-based line number of the error.
columnintThe 1-based column number of the error.
messagestringA message describing the error.
Returns
- bool
trueif the location could be determined;falseotherwise.