Class SerializationHelper
Internal utilities for serialization.
Namespace: TehGM.Wolfringo.Messages.Serialization.Internal
Assembly: Wolfringo.Core.dll
Syntax
public static class SerializationHelper
Remarks
It's not recommended to use this class unless it's required for writing a custom serializer implementation.
Fields
| Improve this Doc View SourceDefaultSerializer
Default serializer.
Declaration
public static readonly JsonSerializer DefaultSerializer
Field Value
Type | Description |
---|---|
Newtonsoft.Json.JsonSerializer |
SerializerSettings
Default serializer settings.
Declaration
public static readonly JsonSerializerSettings SerializerSettings
Field Value
Type | Description |
---|---|
Newtonsoft.Json.JsonSerializerSettings |
Methods
| Improve this Doc View SourceAddAtPath(JObject, String, Object)
Adds a new JProperty at given JsonPath. Note that only dot-notated child syntax is currently supported.
Declaration
public static JProperty AddAtPath(this JObject targetObject, string jsonPath, object content)
Parameters
Type | Name | Description |
---|---|---|
Newtonsoft.Json.Linq.JObject | targetObject | The Newtonsoft.Json.Linq.JObject to add property to. |
String | jsonPath | The JsonPath of the new property. |
Object | content | The property content. |
Returns
Type | Description |
---|---|
Newtonsoft.Json.Linq.JProperty | The created Newtonsoft.Json.Linq.JProperty. |
FlattenCommonProperties<T>(JToken, T, JsonSerializer)
Populates object by "flattening" common properties like "body" or "body.extended" into target object.
Declaration
public static void FlattenCommonProperties<T>(this JToken token, T target, JsonSerializer serializer = null)
Parameters
Type | Name | Description |
---|---|---|
Newtonsoft.Json.Linq.JToken | token | Token to use for populating. |
T | target | Object to populate. |
Newtonsoft.Json.JsonSerializer | serializer | Serializer to use. If null, DefaultSerializer will be used. |
Type Parameters
Name | Description |
---|---|
T | Type of the object. |
Remarks
It's not recommended to use this class unless it's required for writing a custom serializer implementation.
MovePropertyIfExists(ref JObject, ref JObject, String)
Moves json property from one object to another.
Declaration
public static void MovePropertyIfExists(ref JObject source, ref JObject target, string propertyName)
Parameters
Type | Name | Description |
---|---|---|
Newtonsoft.Json.Linq.JObject | source | Object to remove the property from. |
Newtonsoft.Json.Linq.JObject | target | Object to add the property to. |
String | propertyName | Name of the property. |
Remarks
It's not recommended to use this class unless it's required for writing a custom serializer implementation.
PopulateMessageRawData<T>(ref T, IEnumerable<Byte>)
Populates chat message's raw data.
Declaration
public static void PopulateMessageRawData<T>(ref T message, IEnumerable<byte> data)
where T : IRawDataMessage
Parameters
Type | Name | Description |
---|---|---|
T | message | Chat message. |
IEnumerable<Byte> | data | Binary data. |
Type Parameters
Name | Description |
---|---|
T | Type of chat message. |
PopulateObject<T>(JToken, T, String, JsonSerializer)
Populates object with Json token's properties.
Declaration
public static void PopulateObject<T>(this JToken token, T target, string childPath = null, JsonSerializer serializer = null)
Parameters
Type | Name | Description |
---|---|---|
Newtonsoft.Json.Linq.JToken | token | Token to use for populating. |
T | target | Object to populate. |
String | childPath | Selector of the child token in the |
Newtonsoft.Json.JsonSerializer | serializer | Serializer to use. If null, DefaultSerializer will be used. |
Type Parameters
Name | Description |
---|---|
T | Type of the object. |
Remarks
It's not recommended to use this class unless it's required for writing a custom serializer implementation.
SerializeJsonPayload<T>(T, JsonSerializer)
Serializes Wolf message.
Declaration
public static JObject SerializeJsonPayload<T>(this T message, JsonSerializer serializer = null)
where T : IWolfMessage
Parameters
Type | Name | Description |
---|---|---|
T | message | Message to serialize. |
Newtonsoft.Json.JsonSerializer | serializer | Serializer to use. If null, DefaultSerializer will be used. |
Returns
Type | Description |
---|---|
Newtonsoft.Json.Linq.JObject | Serialized message object. |
Type Parameters
Name | Description |
---|---|
T | Type of the message. |
Remarks
It's not recommended to use this class unless it's required for writing a custom serializer implementation.