@Test public void shouldGetTheTypeObjectCorrectly1() { String json = "{\"field\": {}}"; assertEquals(JSONHelpers.getAttributeType(json, "field"), JsonType.OBJECT); }
public static JsonType getAttributeType(String json, String attribute) { try { Object o = JsonPath.read(json, attribute); if (o == null) { return JsonType.NULL; } else if (o instanceof String) { return JsonType.STRING; } else if (o instanceof Integer || o instanceof Double) { return JsonType.INTEGER; } else if (o instanceof JSONArray) { return JsonType.ARRAY; } else if (o instanceof LinkedHashMap) { return JsonType.OBJECT; } else if (o instanceof Boolean) { return JsonType.BOOLEAN; } else { LOGGER.info("Unsupported JSON type."); return null; } } 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 type of an attribute.", e); return null; } catch (IllegalArgumentException e) { LOGGER.info("Wrong arguments passed.", e); return null; } }
JSONHelpers { public static JsonType getAttributeType(String json, String attribute) { try { Object o = JsonPath.read(json, attribute); if (o == null) { return JsonType.NULL; } else if (o instanceof String) { return JsonType.STRING; } else if (o instanceof Integer || o instanceof Double) { return JsonType.INTEGER; } else if (o instanceof JSONArray) { return JsonType.ARRAY; } else if (o instanceof LinkedHashMap) { return JsonType.OBJECT; } else if (o instanceof Boolean) { return JsonType.BOOLEAN; } else { LOGGER.info("Unsupported JSON type."); return null; } } 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 type of an attribute.", e); return null; } catch (IllegalArgumentException e) { LOGGER.info("Wrong arguments passed.", e); return null; } } }
JSONHelpers { public static JsonType getAttributeType(String json, String attribute) { try { Object o = JsonPath.read(json, attribute); if (o == null) { return JsonType.NULL; } else if (o instanceof String) { return JsonType.STRING; } else if (o instanceof Integer || o instanceof Double) { return JsonType.INTEGER; } else if (o instanceof JSONArray) { return JsonType.ARRAY; } else if (o instanceof LinkedHashMap) { return JsonType.OBJECT; } else if (o instanceof Boolean) { return JsonType.BOOLEAN; } else { LOGGER.info("Unsupported JSON type."); return null; } } 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 type of an attribute.", e); return null; } catch (IllegalArgumentException e) { LOGGER.info("Wrong arguments passed.", e); return null; } } private  JSONHelpers(); }
JSONHelpers { public static JsonType getAttributeType(String json, String attribute) { try { Object o = JsonPath.read(json, attribute); if (o == null) { return JsonType.NULL; } else if (o instanceof String) { return JsonType.STRING; } else if (o instanceof Integer || o instanceof Double) { return JsonType.INTEGER; } else if (o instanceof JSONArray) { return JsonType.ARRAY; } else if (o instanceof LinkedHashMap) { return JsonType.OBJECT; } else if (o instanceof Boolean) { return JsonType.BOOLEAN; } else { LOGGER.info("Unsupported JSON type."); return null; } } 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 type 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 JsonType getAttributeType(String json, String attribute) { try { Object o = JsonPath.read(json, attribute); if (o == null) { return JsonType.NULL; } else if (o instanceof String) { return JsonType.STRING; } else if (o instanceof Integer || o instanceof Double) { return JsonType.INTEGER; } else if (o instanceof JSONArray) { return JsonType.ARRAY; } else if (o instanceof LinkedHashMap) { return JsonType.OBJECT; } else if (o instanceof Boolean) { return JsonType.BOOLEAN; } else { LOGGER.info("Unsupported JSON type."); return null; } } 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 type 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);  }