@Test public void parsePropertiesFromJSONBeanTest() throws JsonProcessingException, JSONException { ObjectMapper mapper = new ObjectMapper(); SimpleInputBean bean = new SimpleInputBean(); bean.setA(20); bean.setB(30); String jsonBean = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(bean); Properties properties = JSONBeanUtil.parsePropertiesFromJSONBean(jsonBean); Assert.assertTrue(properties.containsKey("a")); Assert.assertEquals("20", properties.get("a")); Assert.assertTrue(properties.containsKey("b")); Assert.assertEquals("30", properties.get("b")); }
public static Properties parsePropertiesFromJSONBean(final String json) throws JSONException { final Properties properties = new Properties(); final JSONObject obj = new JSONObject(json); @SuppressWarnings("unchecked") final Iterator<String> iterator = obj.keys(); while (iterator.hasNext()) { final String key = iterator.next(); final String value = String.valueOf(obj.get(key)); properties.setProperty(key, value); } return properties; }
JSONBeanUtil { public static Properties parsePropertiesFromJSONBean(final String json) throws JSONException { final Properties properties = new Properties(); final JSONObject obj = new JSONObject(json); @SuppressWarnings("unchecked") final Iterator<String> iterator = obj.keys(); while (iterator.hasNext()) { final String key = iterator.next(); final String value = String.valueOf(obj.get(key)); properties.setProperty(key, value); } return properties; } }
JSONBeanUtil { public static Properties parsePropertiesFromJSONBean(final String json) throws JSONException { final Properties properties = new Properties(); final JSONObject obj = new JSONObject(json); @SuppressWarnings("unchecked") final Iterator<String> iterator = obj.keys(); while (iterator.hasNext()) { final String key = iterator.next(); final String value = String.valueOf(obj.get(key)); properties.setProperty(key, value); } return properties; }  }
JSONBeanUtil { public static Properties parsePropertiesFromJSONBean(final String json) throws JSONException { final Properties properties = new Properties(); final JSONObject obj = new JSONObject(json); @SuppressWarnings("unchecked") final Iterator<String> iterator = obj.keys(); while (iterator.hasNext()) { final String key = iterator.next(); final String value = String.valueOf(obj.get(key)); properties.setProperty(key, value); } return properties; }  static Properties parsePropertiesFromJSONBean(final String json); static String mapToJSONBean(final Map<String,Object> map); }
JSONBeanUtil { public static Properties parsePropertiesFromJSONBean(final String json) throws JSONException { final Properties properties = new Properties(); final JSONObject obj = new JSONObject(json); @SuppressWarnings("unchecked") final Iterator<String> iterator = obj.keys(); while (iterator.hasNext()) { final String key = iterator.next(); final String value = String.valueOf(obj.get(key)); properties.setProperty(key, value); } return properties; }  static Properties parsePropertiesFromJSONBean(final String json); static String mapToJSONBean(final Map<String,Object> map);  }