Source:
public static String parseJson(String inputString, Object schema) throws ValidatorException, ParserException { if (inputString != null && !inputString.isEmpty() && schema instanceof JsonObject) { JsonElement result = null; JsonObject schemaObject = (JsonObject) schema; String type = schemaObject.get(ValidatorConstants.TYPE_KEY).toString().replaceAll( ValidatorConstants.REGEX, ""); if (ValidatorConstants.BOOLEAN_KEYS.contains(type)) { result = BooleanValidator.validateBoolean(schemaObject, inputString); } else if (ValidatorConstants.NOMINAL_KEYS.contains(type)) { result = StringValidator.validateNominal(schemaObject, inputString); } else if (ValidatorConstants.NUMERIC_KEYS.contains(type)) { result = NumericValidator.validateNumeric(schemaObject, inputString); } else if (ValidatorConstants.ARRAY_KEYS.contains(type)) { result = ArrayValidator.validateArray(GSONDataTypeConverter.getMapFromString(inputString), schemaObject); } else if (ValidatorConstants.NULL_KEYS.contains(type)) { NullValidator.validateNull(schemaObject, inputString); result = JsonNull.INSTANCE; } else if (ValidatorConstants.OBJECT_KEYS.contains(type)) { JsonElement input = parser.parse(inputString); if (input.isJsonObject()) { result = ObjectValidator.validateObject(input.getAsJsonObject(), schemaObject); } else { ValidatorException exception = new ValidatorException("Expected a json object input"); logger.error("Expected a JSON as input but found : " + inputString, exception); throw exception; } } if (result != null) { return result.toString(); } return null; } else { ParserException exception = new ParserException("Invalid inputs"); logger.error("Input json and schema should not be null, schema should be a JSON object", exception); throw exception; } }

Target:
private static String parseJson(String inputString, Object schema) throws ValidatorException, ParserException { if (StringUtils.isNotEmpty(inputString) && schema instanceof JsonObject) { JsonElement result = null; JsonObject schemaObject = (JsonObject) schema; if (((JsonObject) schema).has(ValidatorConstants.TYPE_KEY)) { String type = JsonProcessorUtils.replaceEnclosingQuotes( schemaObject.get(ValidatorConstants.TYPE_KEY).toString()); if (ValidatorConstants.BOOLEAN_KEYS.contains(type)) { result = BooleanValidator.validateBoolean(schemaObject, inputString); } else if (ValidatorConstants.NOMINAL_KEYS.contains(type)) { result = StringValidator.validateNominal(schemaObject, inputString); } else if (ValidatorConstants.NUMERIC_KEYS.contains(type)) { result = NumericValidator.validateNumeric(schemaObject, inputString); } else if (ValidatorConstants.ARRAY_KEYS.contains(type)) { result = ArrayValidator.validateArray(GSONDataTypeConverter.getMapFromString(inputString), schemaObject); } else if (ValidatorConstants.NULL_KEYS.contains(type)) { NullValidator.validateNull(schemaObject, inputString); result = JsonNull.INSTANCE; } else if (ValidatorConstants.OBJECT_KEYS.contains(type)) { JsonElement input = parser.parse(inputString); if (input.isJsonObject()) { result = ObjectValidator.validateObject(input.getAsJsonObject(), schemaObject); } else { throw new ValidatorException( "Expected a JSON as input but found : " + inputString); } } if (result != null) { return result.toString(); } return null; } else { throw new ValidatorException("JSON schema should contain a type declaration"); } } else { throw new ParserException("Input json and schema should not be null, " + "schema should be a JSON object"); } }