Class Serialiser<TType>
Represents an implementation of ISerialiser using Newtonsoft Json.NET
Type Parameters
Name | Description |
---|---|
TType | The type of object to serialise |
Constructors
Serialiser()
Constructs a Serialiser without a validator
Declaration
public Serialiser()
Serialiser(AbstractValidator<TType>)
Constructs a Serialiser with a validator
Declaration
public Serialiser(AbstractValidator<TType> validator)
Parameters
Type | Name | Description |
---|---|---|
FluentValidation.AbstractValidator<TType> | validator | The validator to be used when reading JSON |
Methods
FromJson(String, Action<ValidationContext<TType>>)
Deserialises a TType from a JSON string
Declaration
public TType FromJson(string json, Action<ValidationContext<TType>> modifyContext = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | json | The JSON string |
System.Action<FluentValidation.ValidationContext<TType>> | modifyContext | Optional function to modify the context |
Returns
Type | Description |
---|---|
TType | The TType |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | When |
ValidationException | Thrown when validation errors with the de-serialised TType |
Newtonsoft.Json.JsonException | Thrown when a the JSON fails to deserialise |
ToJObject(TType)
Serialises the TType to a JObject
Declaration
public JObject ToJObject(TType obj)
Parameters
Type | Name | Description |
---|---|---|
TType | obj | The TType to serialise |
Returns
Type | Description |
---|---|
Newtonsoft.Json.Linq.JObject | JObject |
ToJson(TType)
Serialises the TType to a JSON UTF-8 string
Declaration
public string ToJson(TType obj)
Parameters
Type | Name | Description |
---|---|---|
TType | obj | The TType to serialise |
Returns
Type | Description |
---|---|
System.String | A UTF-8 JSON string |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | When |
Newtonsoft.Json.JsonException | Thrown when a the JSON fails to serialise |