Photon Quantum 3.0.0

Public Member Functions | Static Public Member Functions | List of all members
Quantum.JsonUtilityExtensions Class Reference

Extends capabilities of JsonUtility by adding type annotations to the serialized JSON, Unity object reference handling and integer enquotement. More...

Public Member Functions

delegate string InstanceIDHandlerDelegate (object context, int value)
 JsonUtilityExtensions.ToJsonWithTypeAnnotation(object,Quantum.JsonUtilityExtensions.InstanceIDHandlerDelegate)
 
delegate Type TypeResolverDelegate (string typeName)
 JsonUtilityExtensions.FromJsonWithTypeAnnotation
 
delegate string TypeSerializerDelegate (Type type)
 JsonUtilityExtensions.ToJsonWithTypeAnnotation(object,Quantum.JsonUtilityExtensions.InstanceIDHandlerDelegate)
 

Static Public Member Functions

static string EnquoteIntegers (string json, int minDigits=8)
 Enquotes integers in the JSON string that are at least minDigits long. This is useful for parsers that interpret large integers as floating point numbers. More...
 
static object FromJsonWithTypeAnnotation (string json, TypeResolverDelegate typeResolver=null)
 Converts JSON with type annotation. If there are no type annotations, use typeResolver to return the expected type. More...
 
static T FromJsonWithTypeAnnotation< T > (string json, TypeResolverDelegate typeResolver=null)
 Converts JSON with type annotation to an instance of T . If the JSON contains type annotations, they need to match the expected result type. If there are no type annotations, use typeResolver to return the expected type. More...
 
static string ToJsonWithTypeAnnotation (object obj, InstanceIDHandlerDelegate instanceIDHandler=null)
 Converts the object to JSON with type annotations. More...
 
static void ToJsonWithTypeAnnotation (object obj, TextWriter writer, int? integerEnquoteMinDigits=null, TypeSerializerDelegate typeSerializer=null, InstanceIDHandlerDelegate instanceIDHandler=null)
 Converts the object/IList to JSON with type annotations. More...
 

Detailed Description

Extends capabilities of JsonUtility by adding type annotations to the serialized JSON, Unity object reference handling and integer enquotement.

Member Function Documentation

◆ EnquoteIntegers()

static string Quantum.JsonUtilityExtensions.EnquoteIntegers ( string  json,
int  minDigits = 8 
)
inlinestatic

Enquotes integers in the JSON string that are at least minDigits long. This is useful for parsers that interpret large integers as floating point numbers.

Parameters
jsonJSON to process
minDigitsDigit threshold to perfom the enquoting
Returns
json with long integers enquoted.

◆ ToJsonWithTypeAnnotation() [1/2]

static string Quantum.JsonUtilityExtensions.ToJsonWithTypeAnnotation ( object  obj,
InstanceIDHandlerDelegate  instanceIDHandler = null 
)
inlinestatic

Converts the object to JSON with type annotations.

Parameters
objObject to be serialized.
instanceIDHandlerHandler for UnityEngine.Object references. If the handler returns an empty string, the reference is removed from the final result.

◆ ToJsonWithTypeAnnotation() [2/2]

static void Quantum.JsonUtilityExtensions.ToJsonWithTypeAnnotation ( object  obj,
TextWriter  writer,
int?  integerEnquoteMinDigits = null,
TypeSerializerDelegate  typeSerializer = null,
InstanceIDHandlerDelegate  instanceIDHandler = null 
)
inlinestatic

Converts the object/IList to JSON with type annotations.

Parameters
objObject to be serialized.
writerThe output TextWriter.
integerEnquoteMinDigitsEnquoteIntegers
typeSerializerHandler for obtaining serialized type names. If null, the short assembly qualified name (namespace + name + assembly name) will be used.
instanceIDHandlerHandler for UnityEngine.Object references. If the handler returns an empty string, the reference is removed from the final result.

◆ FromJsonWithTypeAnnotation< T >()

static T Quantum.JsonUtilityExtensions.FromJsonWithTypeAnnotation< T > ( string  json,
TypeResolverDelegate  typeResolver = null 
)
inlinestatic

Converts JSON with type annotation to an instance of T . If the JSON contains type annotations, they need to match the expected result type. If there are no type annotations, use typeResolver to return the expected type.

Parameters
jsonJSON to be parsed
typeResolverConverts type name to a type instance.

◆ FromJsonWithTypeAnnotation()

static object Quantum.JsonUtilityExtensions.FromJsonWithTypeAnnotation ( string  json,
TypeResolverDelegate  typeResolver = null 
)
inlinestatic

Converts JSON with type annotation. If there are no type annotations, use typeResolver to return the expected type.

Parameters
jsonJSON to be parsed
typeResolverConverts type name to a type instance.