|
|
@@ -16,7 +16,6 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import lombok.experimental.UtilityClass;
|
|
|
|
|
|
@UtilityClass
|
|
|
-
|
|
|
public class JsonHelper {
|
|
|
public List<JsonNode> toArray(final JsonNode array) {
|
|
|
return StreamSupport.stream(array.spliterator(), false).collect(Collectors.toList());
|
|
|
@@ -26,41 +25,18 @@ public class JsonHelper {
|
|
|
return StreamSupport.stream(array.spliterator(), false).map(transform).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- public Set<String> fieldNames(final JsonNode object) {
|
|
|
- Set<String> rval = new HashSet<>();
|
|
|
- object.fieldNames().forEachRemaining(rval::add);
|
|
|
- return rval;
|
|
|
- }
|
|
|
-
|
|
|
public <T> Set<T> fieldNames(final JsonNode object, Function<String, T> transform) {
|
|
|
Set<T> rval = new HashSet<>();
|
|
|
object.fieldNames().forEachRemaining(s -> rval.add(transform.apply(s)));
|
|
|
return rval;
|
|
|
}
|
|
|
-
|
|
|
- public Map<String, JsonNode> fields(final JsonNode object) {
|
|
|
- Map<String, JsonNode> rval = new HashMap<>();
|
|
|
- object.fields().forEachRemaining(pair -> rval.put(pair.getKey(), pair.getValue()));
|
|
|
- return rval;
|
|
|
- }
|
|
|
-
|
|
|
- public <T> Map<String, T> fields(final JsonNode object, Function<JsonNode, T> transform) {
|
|
|
- Map<String, T> rval = new HashMap<>();
|
|
|
- object.fields().forEachRemaining(pair -> rval.put(pair.getKey(), transform.apply(pair.getValue())));
|
|
|
- return rval;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
public <T> Map<String, T> fields(final JsonNode object, BiFunction<String, JsonNode, T> transform) {
|
|
|
Map<String, T> rval = new HashMap<>();
|
|
|
object.fields().forEachRemaining(pair -> rval.put(pair.getKey(),
|
|
|
transform.apply(pair.getKey(), pair.getValue())));
|
|
|
return rval;
|
|
|
}
|
|
|
- public <T> List<T> values(final JsonNode object, Function<JsonNode, T> transform) {
|
|
|
- List<T> rval = new ArrayList<>();
|
|
|
- object.fields().forEachRemaining(pair -> rval.add(transform.apply(pair.getValue())));
|
|
|
- return rval;
|
|
|
- }
|
|
|
|
|
|
public <T> List<T> values(final JsonNode object, BiFunction<String, JsonNode, T> transform) {
|
|
|
List<T> rval = new ArrayList<>();
|