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

ee.telekom.workflow.web.util.JsonParserUtil Maven / Gradle / Ivy

Go to download

Telekom-workflow-engine web console, REST services and JMX interface for monitoring and interacting with the running engine.

The newest version!
package ee.telekom.workflow.web.util;

import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

/**
 * Utility to provide NULL safe manual Json parsing operations
 */
public class JsonParserUtil{

    private static final JsonParser parser = new JsonParser();

    public static JsonObject parseJson( String body ){
        return parser.parse( body ).getAsJsonObject();
    }

    public static String getAsNullSafeString( JsonObject object, String memberName ){
        if( object != null ){
            JsonElement element = object.get( memberName );
            return element == null || element instanceof JsonNull ? null : element.getAsString();
        }
        return null;
    }

    public static Integer getAsNullSafeInteger( JsonObject object, String memberName ){
        if( object != null ){
            JsonElement element = object.get( memberName );
            return element == null || element instanceof JsonNull ? null : element.getAsInt();
        }
        return null;
    }

    public static String toNullSafeJsonString( JsonObject object, String memberName ){
        if( object != null ){
            JsonElement element = object.get( memberName );
            return element != null ? element.toString() : null;
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy