com.graphql_java_generator.server.util.JsonKit Maven / Gradle / Ivy
package com.graphql_java_generator.server.util;
import java.util.Collections;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
/**
* This example code chose to use GSON as its JSON parser. Any JSON parser should be fine
*/
public class JsonKit {
private static final Gson GSON = new GsonBuilder()
//
// This is important because the graphql spec says that null values should be present
//
.serializeNulls().create();
public static Map toMap(String jsonStr) {
if (jsonStr == null || jsonStr.trim().length() == 0) {
return Collections.emptyMap();
}
// gson uses type tokens for generic input like Map
TypeToken
© 2015 - 2025 Weber Informatics LLC | Privacy Policy