Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.paypal.base.rest;
 
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(s):
kjayakumar
public final class JSONFormatter {
	/*
	 * JSONFormatter is coupled to the stubs generated using the SDK generator.
	 * Since PayPal REST APIs support only JSON, this class is bound to the
	 * stubs for their json representation.
	 */
	private JSONFormatter() {
	}

FieldNamingPolicy used by the underlying Gson library. Alter this property to set a fieldnamingpolicy other than LOWER_CASE_WITH_UNDERSCORES used by PayPal REST APIs
Gson
	public static Gson GSON = new GsonBuilder().setPrettyPrinting()
Set a format for gson FIELD_NAMING_POLICY. See com.google.gson.FieldNamingPolicy

Parameters:
FIELD_NAMING_POLICY
	public static final void setFIELD_NAMING_POLICY(
			FieldNamingPolicy FIELD_NAMING_POLICY) {
				.setFieldNamingPolicy(FIELD_NAMING_POLICY).create();
	}

Converts a Raw Type to JSON String

Parameters:
<T> Type to be converted
t Object of the type
Returns:
JSON representation
	public static <T> String toJSON(T t) {
		return .toJson(t);
	}

Converts a JSON String to object representation

Parameters:
<T> Type to be converted
responseString JSON representation
clazz Target class
Returns:
Object of the target type
	public static <T> T fromJSON(String responseStringClass<T> clazz) {
t = null;
		if (clazz.isAssignableFrom(responseString.getClass())) {
			t = clazz.cast(responseString);
else {
			t = .fromJson(responseStringclazz);
		}
		return t;
	}
New to GrepCode? Check out our FAQ X