@Test public void arrayToJsonBeans() throws IOException { ObjectReader reader = JsonUtils.reader(); assertThat(JsonUtils.arrayToJsonBeans(reader.readTree("{}"))).isEqualTo(Collections.emptyList()); assertThat(JsonUtils.arrayToJsonBeans(reader.readTree("{\"foo\": \"bar\"}"))).isEqualTo(Collections.emptyList()); assertThat(JsonUtils.arrayToJsonBeans(reader.readTree("[]"))).isEqualTo(Collections.emptyList()); assertThat(JsonUtils.arrayToJsonBeans(reader.readTree("[{\"foo\": \"bar\"}]"))).isEqualTo(Collections.singletonList("{\"foo\":\"bar\"}")); assertThat(JsonUtils.arrayToJsonBeans(reader.readTree("[{\"foo1\": \"bar1\"}, {\"foo2\": \"bar2\"}]"))).isEqualTo(Arrays.asList("{\"foo1\":\"bar1\"}", "{\"foo2\":\"bar2\"}")); }
public static List<String> arrayToJsonBeans(JsonNode json) throws JsonProcessingException { List<String> jsonBeans = new ArrayList<>(); if (json.isArray()) { Iterator<JsonNode> it = json.elements(); while (it.hasNext()) { jsonBeans.add(writer().writeValueAsString(it.next())); } return jsonBeans; } return jsonBeans; }
JsonUtils { public static List<String> arrayToJsonBeans(JsonNode json) throws JsonProcessingException { List<String> jsonBeans = new ArrayList<>(); if (json.isArray()) { Iterator<JsonNode> it = json.elements(); while (it.hasNext()) { jsonBeans.add(writer().writeValueAsString(it.next())); } return jsonBeans; } return jsonBeans; } }
JsonUtils { public static List<String> arrayToJsonBeans(JsonNode json) throws JsonProcessingException { List<String> jsonBeans = new ArrayList<>(); if (json.isArray()) { Iterator<JsonNode> it = json.elements(); while (it.hasNext()) { jsonBeans.add(writer().writeValueAsString(it.next())); } return jsonBeans; } return jsonBeans; } private  JsonUtils(); }
JsonUtils { public static List<String> arrayToJsonBeans(JsonNode json) throws JsonProcessingException { List<String> jsonBeans = new ArrayList<>(); if (json.isArray()) { Iterator<JsonNode> it = json.elements(); while (it.hasNext()) { jsonBeans.add(writer().writeValueAsString(it.next())); } return jsonBeans; } return jsonBeans; } private  JsonUtils(); static ObjectReader reader(); static T readFromStream(final InputStream stream, final Class<T> type); static ObjectWriter writer(); static ObjectMapper copyObjectMapperConfiguration(); static Map<String, Object> map(Object... values); static T convertValue(final Object fromValue, final Class<T> toValueType); static boolean isJson(String value); static boolean isJsonObject(String value); static boolean isJsonArray(String value); static List<String> arrayToJsonBeans(JsonNode json); static String jsonBeansToArray(List<?> jsonBeans); static String toPrettyString(Object value); static String toString(Object value); }
JsonUtils { public static List<String> arrayToJsonBeans(JsonNode json) throws JsonProcessingException { List<String> jsonBeans = new ArrayList<>(); if (json.isArray()) { Iterator<JsonNode> it = json.elements(); while (it.hasNext()) { jsonBeans.add(writer().writeValueAsString(it.next())); } return jsonBeans; } return jsonBeans; } private  JsonUtils(); static ObjectReader reader(); static T readFromStream(final InputStream stream, final Class<T> type); static ObjectWriter writer(); static ObjectMapper copyObjectMapperConfiguration(); static Map<String, Object> map(Object... values); static T convertValue(final Object fromValue, final Class<T> toValueType); static boolean isJson(String value); static boolean isJsonObject(String value); static boolean isJsonArray(String value); static List<String> arrayToJsonBeans(JsonNode json); static String jsonBeansToArray(List<?> jsonBeans); static String toPrettyString(Object value); static String toString(Object value);  }