ioinformarics.oss.jackson.module.jsonld.util.JsonUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-jsonld Show documentation
Show all versions of jackson-jsonld Show documentation
JSON-LD Module for Jackson
The newest version!
package ioinformarics.oss.jackson.module.jsonld.util;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.Iterator;
/**
* @author Alexander De Leon ([email protected])
*/
public abstract class JsonUtils {
public static JsonNode merge(JsonNode mainNode, JsonNode updateNode) {
Iterator fieldNames = updateNode.fieldNames();
while (fieldNames.hasNext()) {
String fieldName = fieldNames.next();
JsonNode jsonNode = mainNode.get(fieldName);
// if field exists and is an embedded object
if (jsonNode != null && jsonNode.isObject()) {
merge(jsonNode, updateNode.get(fieldName));
}
else {
if (mainNode instanceof ObjectNode) {
// Overwrite field
JsonNode value = updateNode.get(fieldName);
((ObjectNode) mainNode).set(fieldName, value);
}
}
}
return mainNode;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy