JsonCollectors { public static Collector<JsonField, JsonArrayBuilder, JsonArray> fieldKeysToArray() { return Collector.of(JsonFactory::newArrayBuilder, (arrayBuilder, field) -> arrayBuilder.add(field.getKeyName()), JsonArrayBuilder::addAll, JsonArrayBuilder::build); } private  JsonCollectors(); static Collector<JsonField, JsonObjectBuilder, JsonObject> fieldsToObject(); static Collector<JsonObject, JsonObjectBuilder, JsonObject> objectsToObject(); static Collector<JsonField, JsonArrayBuilder, JsonArray> fieldKeysToArray(); static Collector<JsonField, JsonArrayBuilder, JsonArray> fieldValuesToArray(); static Collector<JsonValue, JsonArrayBuilder, JsonArray> valuesToArray();  }
@Test public void collectingFieldKeysOfObjectReturnsExpectedArray() { final JsonArray expectedArray = JsonFactory.newArrayBuilder() .add(JsonFactory.newValue(ID_KEY.toString())) .add(JsonFactory.newValue(STATE_KEY.toString())) .add(JsonFactory.newValue(MANUFACTURER_KEY.toString())) .build(); final JsonArray actualArray = KNOWN_JSON_OBJECT.stream() .collect(JsonCollectors.fieldKeysToArray()); DittoJsonAssertions.assertThat(actualArray).isEqualTo(expectedArray); }