All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kazurayam.ks.globalvariable.JsonUtil.groovy Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package com.kazurayam.ks.globalvariable

import com.google.gson.Gson
import com.google.gson.GsonBuilder

public class JsonUtil {

	public static String prettyPrint(String sourceJson) {
		return prettyPrint(sourceJson, Map.class);
	}

	public static  String prettyPrint(String sourceJson, Class clazz) {
		Gson gson = new GsonBuilder().setPrettyPrinting().create();
		// parse JSON text to a Map
		Object obj = gson.fromJson(sourceJson, clazz);
		// serialize the object back to a JSON text in pretty-print format
		return gson.toJson(obj);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy