com.paypal.base.rest
Class JSONFormatter

java.lang.Object
  extended by com.paypal.base.rest.JSONFormatter

public final class JSONFormatter
extends Object

JSONFormatter converts objects to JSON representation and vice-versa. This class depends on Google's GSON library to do the transformation. This class is not thread-safe.

Author:
kjayakumar

Field Summary
static com.google.gson.Gson GSON
          Gson
 
Method Summary
static
<T> T
fromJSON(String responseString, Class<T> clazz)
          Converts a JSON String to object representation
static void setFIELD_NAMING_POLICY(com.google.gson.FieldNamingPolicy FIELD_NAMING_POLICY)
          Set a format for gson FIELD_NAMING_POLICY.
static
<T> String
toJSON(T t)
          Converts a Raw Type to JSON String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GSON

public static com.google.gson.Gson GSON
Gson

Method Detail

setFIELD_NAMING_POLICY

public static final void setFIELD_NAMING_POLICY(com.google.gson.FieldNamingPolicy FIELD_NAMING_POLICY)
Set a format for gson FIELD_NAMING_POLICY. See FieldNamingPolicy

Parameters:
FIELD_NAMING_POLICY -

toJSON

public static <T> String toJSON(T t)
Converts a Raw Type to JSON String

Type Parameters:
T - Type to be converted
Parameters:
t - Object of the type
Returns:
JSON representation

fromJSON

public static <T> T fromJSON(String responseString,
                             Class<T> clazz)
Converts a JSON String to object representation

Type Parameters:
T - Type to be converted
Parameters:
responseString - JSON representation
clazz - Target class
Returns:
Object of the target type


Copyright © 2015. All Rights Reserved.