@Test public void shouldReturnNullIfJSONPathIsInvalidOnGetValue() { assertNull(JSONHelpers.getAttributeValue(JSON, "(field")); }
public static String getAttributeValue(String json, String attribute) { try { String value = JsonPath.read(json, attribute).toString(); LOGGER.info("The attribute '{}' has the value '{}' in the body '{}'.", attribute, value, json); return value; } catch (InvalidJsonException e) { LOGGER.info("JSON was not valid, e.g. the body was empty.", e); return null; } catch (InvalidPathException e) { LOGGER.info("Could not parse the JSON to get the value of an attribute.", e); return null; } catch (IllegalArgumentException e) { LOGGER.info("Wrong arguments passed.", e); return null; } }
JSONHelpers { public static String getAttributeValue(String json, String attribute) { try { String value = JsonPath.read(json, attribute).toString(); LOGGER.info("The attribute '{}' has the value '{}' in the body '{}'.", attribute, value, json); return value; } catch (InvalidJsonException e) { LOGGER.info("JSON was not valid, e.g. the body was empty.", e); return null; } catch (InvalidPathException e) { LOGGER.info("Could not parse the JSON to get the value of an attribute.", e); return null; } catch (IllegalArgumentException e) { LOGGER.info("Wrong arguments passed.", e); return null; } } }
JSONHelpers { public static String getAttributeValue(String json, String attribute) { try { String value = JsonPath.read(json, attribute).toString(); LOGGER.info("The attribute '{}' has the value '{}' in the body '{}'.", attribute, value, json); return value; } catch (InvalidJsonException e) { LOGGER.info("JSON was not valid, e.g. the body was empty.", e); return null; } catch (InvalidPathException e) { LOGGER.info("Could not parse the JSON to get the value of an attribute.", e); return null; } catch (IllegalArgumentException e) { LOGGER.info("Wrong arguments passed.", e); return null; } } private  JSONHelpers(); }
JSONHelpers { public static String getAttributeValue(String json, String attribute) { try { String value = JsonPath.read(json, attribute).toString(); LOGGER.info("The attribute '{}' has the value '{}' in the body '{}'.", attribute, value, json); return value; } catch (InvalidJsonException e) { LOGGER.info("JSON was not valid, e.g. the body was empty.", e); return null; } catch (InvalidPathException e) { LOGGER.info("Could not parse the JSON to get the value of an attribute.", e); return null; } catch (IllegalArgumentException e) { LOGGER.info("Wrong arguments passed.", e); return null; } } private  JSONHelpers(); static String getAttributeValue(String json, String attribute); static JsonType getAttributeType(String json, String attribute); }
JSONHelpers { public static String getAttributeValue(String json, String attribute) { try { String value = JsonPath.read(json, attribute).toString(); LOGGER.info("The attribute '{}' has the value '{}' in the body '{}'.", attribute, value, json); return value; } catch (InvalidJsonException e) { LOGGER.info("JSON was not valid, e.g. the body was empty.", e); return null; } catch (InvalidPathException e) { LOGGER.info("Could not parse the JSON to get the value of an attribute.", e); return null; } catch (IllegalArgumentException e) { LOGGER.info("Wrong arguments passed.", e); return null; } } private  JSONHelpers(); static String getAttributeValue(String json, String attribute); static JsonType getAttributeType(String json, String attribute);  }