Pip-Services-Commons-Dotnet
Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
PipServices3.Commons.Convert.JsonConverter Class Reference

Converts arbitrary values from and to JSON (JavaScript Object Notation) strings. More...

Static Public Member Functions

static string ToJson (object value)
 Converts value into JSON string. More...
 
static object FromJson (string value)
 Converts value from JSON string More...
 
static T FromJson< T > (string value)
 Converts value from JSON string to T object More...
 
static IDictionary< string, object > ToNullableMap (string value)
 Converts JSON string into map object or returns null when conversion is not possible. More...
 
static IDictionary< string, object > ToMap (string value)
 Converts JSON string into map object or returns empty map when conversion is not possible. More...
 
static IDictionary< string, object > ToMapWithDefault (string value, IDictionary< string, object > defaultValue)
 Converts JSON string into map object or returns default map when conversion is not possible. More...
 

Static Private Member Functions

static void ConvertJsonTypes (IDictionary< string, object > dict)
 
static void ConvertJsonTypes (IList< object > list)
 

Static Private Attributes

static JsonSerializerSettings JsonSettings
 

Detailed Description

Converts arbitrary values from and to JSON (JavaScript Object Notation) strings.

var value1 = JsonConverter.fromJson("{\"key\":123}"); // Result: { key: 123 }
var value2 = JsonConverter.ToMap({ key: 123}); // Result: "{\"key\":123}"

Member Function Documentation

◆ FromJson()

static object PipServices3.Commons.Convert.JsonConverter.FromJson ( string  value)
static

Converts value from JSON string

Parameters
valuethe JSON string to convert.
Returns
converted object value or null when value is null.

◆ FromJson< T >()

static T PipServices3.Commons.Convert.JsonConverter.FromJson< T > ( string  value)
static

Converts value from JSON string to T object

Template Parameters
T
Parameters
valuethe JSON string to convert.
Returns
converted object value or null when value is null.

◆ ToJson()

static string PipServices3.Commons.Convert.JsonConverter.ToJson ( object  value)
static

Converts value into JSON string.

Parameters
valuethe value to convert
Returns
JSON string or null when value is null.

◆ ToMap()

static IDictionary<string, object> PipServices3.Commons.Convert.JsonConverter.ToMap ( string  value)
static

Converts JSON string into map object or returns empty map when conversion is not possible.

Parameters
valuethe JSON string to convert.
Returns
Map object value or empty map when conversion is not supported.

◆ ToMapWithDefault()

static IDictionary<string, object> PipServices3.Commons.Convert.JsonConverter.ToMapWithDefault ( string  value,
IDictionary< string, object >  defaultValue 
)
static

Converts JSON string into map object or returns default map when conversion is not possible.

Parameters
valuethe JSON string to convert.
defaultValuethe default value.
Returns
Map object value or default map when conversion is not supported.

◆ ToNullableMap()

static IDictionary<string, object> PipServices3.Commons.Convert.JsonConverter.ToNullableMap ( string  value)
static

Converts JSON string into map object or returns null when conversion is not possible.

Parameters
valuethe JSON string to convert.
Returns
Map object value or null when conversion is not supported.

Member Data Documentation

◆ JsonSettings

JsonSerializerSettings PipServices3.Commons.Convert.JsonConverter.JsonSettings
staticprivate
Initial value:
= new JsonSerializerSettings
{
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
DateFormatHandling = DateFormatHandling.IsoDateFormat,
NullValueHandling = NullValueHandling.Ignore,
Converters = new List<Newtonsoft.Json.JsonConverter>
{
new Newtonsoft.Json.Converters.StringEnumConverter()
}
}

The documentation for this class was generated from the following file: