ee.telekom.workflow.web.util.JsonParserUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of workflow-web Show documentation
Show all versions of workflow-web Show documentation
Telekom-workflow-engine web console, REST services and JMX interface for monitoring and interacting with the running engine.
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 - 2025 Weber Informatics LLC | Privacy Policy