cfboom.gson

Class Gson

lucee.Component
    extended by cfboom.lang.Object
      extended by cfboom.gson.Gson

A wrapper facade to the gson project (https://www.javadoc.io/doc/com.google.code.gson/gson/).

Class Attributes:
  • singleton : true
  •  
  • output : false
  •  
  • displayname : Class Gson
  •  
  • synchronized : false
  •  
  • accessors : false
  •  
  • persistent : false
  •  
  • author : Joel Tobey
  •  
    Property Summary
    type property default serializable required
    any loader


    • access = public
    • returntype = any
    • inject = javaLoader@cfboomGson
    true false
    any log


    • access = public
    • returntype = any
    • inject = logbox:logger:{this}
    true false
    any populator


    • access = public
    • returntype = any
    • inject = wirebox:populator
    true false
    any wirebox


    • access = public
    • returntype = any
    • inject = wirebox
    true false
    Constructor Summary
    init()
    Method Summary
    any fromJson(string json, string class)
         This method deserializes the specified Json into an object of the specified class.
    any newJsonReader(any reader)
         Returns a new JSON reader configured for the settings on this Gson instance.
    any newJsonWriter(any writer)
         Returns a new JSON writer configured for the settings on this Gson instance.
    void onDIComplete()
    void registerTypeAdapter(string type, TypeAdapter typeAdapter)
         Configures Gson for custom serialization or deserialization.
    string toJson(any src)
         This method serializes the specified object into its equivalent Json representation.
     
    Methods inherited from class cfboom.lang.Object
    $equals, getComponentName, getIdentityHashCode, getIdentityString, getMeta, hashCode, toString
     
    Methods inherited from class lucee.Component
    None

    Constructor Detail

    init

    public init()


    Property Detail

    loader

    property any loader

    Attributes:
    access - public
    required - false
    returntype - any
    inject - javaLoader@cfboomGson
    serializable - true

    log

    property any log

    Attributes:
    access - public
    required - false
    returntype - any
    inject - logbox:logger:{this}
    serializable - true

    populator

    property any populator

    Attributes:
    access - public
    required - false
    returntype - any
    inject - wirebox:populator
    serializable - true

    wirebox

    property any wirebox

    Attributes:
    access - public
    required - false
    returntype - any
    inject - wirebox
    serializable - true

    Method Detail

    fromJson

    public any fromJson(string json, string class)

    This method deserializes the specified Json into an object of the specified class.

    Parameters:
    json - the string from which the object is to be deserialized
    class - the class of the desired object
    Returns:
    an object of the specified class. Returns null if json is null or if json is empty.

    newJsonReader

    public any newJsonReader(any reader)

    Returns a new JSON reader configured for the settings on this Gson instance.

    Parameters:
    reader - A java.io.Reader

    newJsonWriter

    public any newJsonWriter(any writer)

    Returns a new JSON writer configured for the settings on this Gson instance.

    Parameters:
    writer - A java.io.Writer

    onDIComplete

    public void onDIComplete()


    registerTypeAdapter

    public void registerTypeAdapter(string type, TypeAdapter typeAdapter)

    Configures Gson for custom serialization or deserialization. Overwrites any previously registered TypeAdapter with the same type.

    Parameters:
    type - Class as defined in getComponentMeta().fullname
    typeAdapter - This object must extend cfboom.gson.TypeAdapter.

    toJson

    public string toJson(any src)

    This method serializes the specified object into its equivalent Json representation.

    Parameters:
    src - the object for which Json representation is to be created setting for Gson
    Returns:
    Json representation of src.