@Test public void parseSqlParametersFromJSONBeanWhenNoParameters() throws JsonProcessingException { try { String[] jsonParamValues = { null, "", "{}", "[]", "something else" }; for (int i = 0; i < jsonParamValues.length; ++i) { Map<String, SqlParameterValue> retMap = JSONBeanUtil.parseSqlParametersFromJSONBean(jsonParamValues[i], new HashMap<>()); assertThat(retMap).isEmpty(); } } catch (Exception ex) { throw new AssertionError("Should not throw exception when json parameter is empty", ex); } try { String jsonParamValue = "{ \"arg1\": \"blah\" }"; Map<String, SqlParameterValue> retMap = JSONBeanUtil.parseSqlParametersFromJSONBean(jsonParamValue, null); SqlParameterValue paramValue = retMap.get("arg1"); assertNotNull(paramValue); assertEquals(Types.VARCHAR, paramValue.getSqlType()); } catch (Exception ex) { throw new AssertionError("Should not throw exception when json parameter is empty", ex); } }
public static Map<String, SqlParameterValue> parseSqlParametersFromJSONBean(final String json, final Map<String, Integer> jdbcTypeMap) { if (!isValidJSONBean(json)) { return Collections.emptyMap(); } final Map<String, String> parsed; try { parsed = MAPPER.readerFor(STRING_STRING_MAP).readValue(json); } catch (final IOException e) { throw new IllegalArgumentException("Unable to parse given JSON", e); } final Map<String,SqlParameterValue> ret = new HashMap<>(); for (Map.Entry<String, String> entry : parsed.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); Integer jdbcType = null; if (jdbcTypeMap != null) { jdbcType = jdbcTypeMap.get(key); } if (jdbcType == null) { jdbcType = Types.VARCHAR; } SqlParameterValue sqlParam = new SqlParameterValue(jdbcType, value); ret.put(key, sqlParam); } return Collections.unmodifiableMap(ret); }
JSONBeanUtil { public static Map<String, SqlParameterValue> parseSqlParametersFromJSONBean(final String json, final Map<String, Integer> jdbcTypeMap) { if (!isValidJSONBean(json)) { return Collections.emptyMap(); } final Map<String, String> parsed; try { parsed = MAPPER.readerFor(STRING_STRING_MAP).readValue(json); } catch (final IOException e) { throw new IllegalArgumentException("Unable to parse given JSON", e); } final Map<String,SqlParameterValue> ret = new HashMap<>(); for (Map.Entry<String, String> entry : parsed.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); Integer jdbcType = null; if (jdbcTypeMap != null) { jdbcType = jdbcTypeMap.get(key); } if (jdbcType == null) { jdbcType = Types.VARCHAR; } SqlParameterValue sqlParam = new SqlParameterValue(jdbcType, value); ret.put(key, sqlParam); } return Collections.unmodifiableMap(ret); } }
JSONBeanUtil { public static Map<String, SqlParameterValue> parseSqlParametersFromJSONBean(final String json, final Map<String, Integer> jdbcTypeMap) { if (!isValidJSONBean(json)) { return Collections.emptyMap(); } final Map<String, String> parsed; try { parsed = MAPPER.readerFor(STRING_STRING_MAP).readValue(json); } catch (final IOException e) { throw new IllegalArgumentException("Unable to parse given JSON", e); } final Map<String,SqlParameterValue> ret = new HashMap<>(); for (Map.Entry<String, String> entry : parsed.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); Integer jdbcType = null; if (jdbcTypeMap != null) { jdbcType = jdbcTypeMap.get(key); } if (jdbcType == null) { jdbcType = Types.VARCHAR; } SqlParameterValue sqlParam = new SqlParameterValue(jdbcType, value); ret.put(key, sqlParam); } return Collections.unmodifiableMap(ret); } private  JSONBeanUtil(); }
JSONBeanUtil { public static Map<String, SqlParameterValue> parseSqlParametersFromJSONBean(final String json, final Map<String, Integer> jdbcTypeMap) { if (!isValidJSONBean(json)) { return Collections.emptyMap(); } final Map<String, String> parsed; try { parsed = MAPPER.readerFor(STRING_STRING_MAP).readValue(json); } catch (final IOException e) { throw new IllegalArgumentException("Unable to parse given JSON", e); } final Map<String,SqlParameterValue> ret = new HashMap<>(); for (Map.Entry<String, String> entry : parsed.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); Integer jdbcType = null; if (jdbcTypeMap != null) { jdbcType = jdbcTypeMap.get(key); } if (jdbcType == null) { jdbcType = Types.VARCHAR; } SqlParameterValue sqlParam = new SqlParameterValue(jdbcType, value); ret.put(key, sqlParam); } return Collections.unmodifiableMap(ret); } private  JSONBeanUtil(); static Properties parsePropertiesFromJSONBean(final String json); static Map<String, SqlParameterValue> parseSqlParametersFromJSONBean(final String json, final Map<String, Integer> jdbcTypeMap); @SuppressWarnings("unchecked") static String toJSONBean(final List<Object> list); static String toJSONBean(final Map<String, Object> map); static List<String> toJSONBeans(Message in); static List<String> toJSONBeansFromHeader(Message in, String autoIncrementColumnName); }
JSONBeanUtil { public static Map<String, SqlParameterValue> parseSqlParametersFromJSONBean(final String json, final Map<String, Integer> jdbcTypeMap) { if (!isValidJSONBean(json)) { return Collections.emptyMap(); } final Map<String, String> parsed; try { parsed = MAPPER.readerFor(STRING_STRING_MAP).readValue(json); } catch (final IOException e) { throw new IllegalArgumentException("Unable to parse given JSON", e); } final Map<String,SqlParameterValue> ret = new HashMap<>(); for (Map.Entry<String, String> entry : parsed.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); Integer jdbcType = null; if (jdbcTypeMap != null) { jdbcType = jdbcTypeMap.get(key); } if (jdbcType == null) { jdbcType = Types.VARCHAR; } SqlParameterValue sqlParam = new SqlParameterValue(jdbcType, value); ret.put(key, sqlParam); } return Collections.unmodifiableMap(ret); } private  JSONBeanUtil(); static Properties parsePropertiesFromJSONBean(final String json); static Map<String, SqlParameterValue> parseSqlParametersFromJSONBean(final String json, final Map<String, Integer> jdbcTypeMap); @SuppressWarnings("unchecked") static String toJSONBean(final List<Object> list); static String toJSONBean(final Map<String, Object> map); static List<String> toJSONBeans(Message in); static List<String> toJSONBeansFromHeader(Message in, String autoIncrementColumnName);  }