Class SerializerHelperJson
- Namespace
- SunamoJson
- Assembly
- SunamoJson.dll
Helper class for JSON serialization and deserialization.
public static class SerializerHelperJson
- Inheritance
-
SerializerHelperJson
- Inherited Members
Methods
ReadFromJsonFile<T>(ILogger, string, ReadFromJsonFileArgs)
Reads an object instance from a JSON file.
Object type must have a parameterless constructor.
public static Task<T?> ReadFromJsonFile<T>(ILogger logger, string path, ReadFromJsonFileArgs args) where T : new()
Parameters
loggerILoggerThe logger instance for error logging.
pathstringThe file path to read the object instance from.
argsReadFromJsonFileArgsArguments for controlling the read behavior.
Returns
- Task<T>
Returns a new instance of the object read from the JSON file, or null if deserialization fails.
Type Parameters
TThe type of object to read from the file.
WriteToJsonFile<T>(ILogger, string, T, WriteToJsonFileArgs?)
Writes the given object instance to a JSON file.
Object type must have a parameterless constructor.
Only public properties and variables will be written to the file. These can be any type though, even other classes.
If there are public properties/variables that you do not want written to the file, decorate them with the [JsonIgnore] attribute.
public static Task<bool> WriteToJsonFile<T>(ILogger logger, string path, T objectToWrite, WriteToJsonFileArgs? args = null) where T : new()
Parameters
loggerILoggerThe logger instance for error logging.
pathstringThe file path to write the object instance to.
objectToWriteTThe object instance to write to the file.
argsWriteToJsonFileArgsOptional arguments for controlling the write behavior.
Returns
Type Parameters
TThe type of object being written to the file.