Example usage for com.fasterxml.jackson.databind.node ObjectNode get

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode get.

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:com.collective.celos.Util.java

public static int getIntProperty(ObjectNode properties, String name) {
    JsonNode node = properties.get(name);
    if (node == null) {
        throw new IllegalArgumentException("Property " + name + " not set.");
    } else if (!node.isInt()) {
        throw new IllegalArgumentException("Property " + name + " is not an integer, but " + node);
    } else {/*w  w w. ja v a2  s .com*/
        return node.intValue();
    }
}

From source file:com.collective.celos.Util.java

public static ArrayNode getArrayProperty(ObjectNode properties, String name) {
    JsonNode node = properties.get(name);
    if (node == null) {
        throw new IllegalArgumentException("Property " + name + " not set.");
    } else if (!node.isArray()) {
        throw new IllegalArgumentException("Property " + name + " is not an array, but " + node);
    } else {/*from  w w  w.  jav a2  s  . c  om*/
        return (ArrayNode) node;
    }
}

From source file:com.collective.celos.Util.java

public static ObjectNode getObjectProperty(ObjectNode properties, String name) {
    JsonNode node = properties.get(name);
    if (node == null) {
        throw new IllegalArgumentException("Property " + name + " not set.");
    } else if (!node.isObject()) {
        throw new IllegalArgumentException("Property " + name + " is not an object, but " + node);
    } else {//from www .  j ava2 s .c o  m
        return (ObjectNode) node;
    }
}

From source file:com.youtube.serializer.YoutubeEventClassifier.java

public static Class detectClass(String json) {
    Preconditions.checkNotNull(json);/*  w ww.j a  v a2 s  .  com*/
    Preconditions.checkArgument(StringUtils.isNotEmpty(json));

    ObjectNode objectNode;
    try {
        objectNode = (ObjectNode) mapper.readTree(json);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

    if (objectNode.findValue("kind") != null && objectNode.get("kind").toString().equals(VIDEO_IDENTIFIER)) {
        return Video.class;
    } else if (objectNode.findValue("kind") != null
            && objectNode.get("kind").toString().contains(CHANNEL_IDENTIFIER)) {
        return com.google.api.services.youtube.model.Channel.class;
    } else {
        return ObjectNode.class;
    }
}

From source file:com.google.gplus.serializer.util.GPlusEventClassifier.java

public static Class detectClass(String json) {
    Preconditions.checkNotNull(json);/*w  w w.j ava  2 s.c o m*/
    Preconditions.checkArgument(StringUtils.isNotEmpty(json));

    ObjectNode objectNode;
    try {
        objectNode = (ObjectNode) mapper.readTree(json);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

    if (objectNode.findValue("kind") != null && objectNode.get("kind").toString().equals(ACTIVITY_IDENTIFIER)) {
        return Activity.class;
    } else if (objectNode.findValue("kind") != null
            && objectNode.get("kind").toString().equals(PERSON_IDENTIFIER)) {
        return Person.class;
    } else {
        return ObjectNode.class;
    }
}

From source file:com.google.api.server.spi.tools.JacksonUtil.java

public static ObjectNode mergeObject(ObjectNode object1, ObjectNode object2, boolean throwOnConflict) {
    Iterator<String> fieldNames = object2.fieldNames();
    while (fieldNames.hasNext()) {
        String fieldName = fieldNames.next();
        JsonNode child2 = object2.get(fieldName);
        JsonNode child1 = object1.get(fieldName);
        JsonNode merged = (child1 == null) ? child2 : mergeNode(child1, child2, throwOnConflict);
        object1.put(fieldName, merged);//  ww  w  . j  a  v a  2  s .  c  om
    }
    return object1;
}

From source file:org.gitana.platform.client.util.DriverUtil.java

public static ACL toACL(Response response) {
    ACL acl = new ACL();

    ObjectNode objectNode = response.getObjectNode();
    ArrayNode rows = (ArrayNode) objectNode.get("rows");
    for (int x = 0; x < rows.size(); x++) {
        ObjectNode binding = (ObjectNode) rows.get(x);

        String principalId = binding.get(DomainPrincipal.FIELD_ID).textValue();
        String principalType = binding.get(DomainPrincipal.FIELD_TYPE).textValue();

        List<String> roles = new ArrayList<String>();
        ArrayNode array = (ArrayNode) binding.get("authorities");
        for (int i = 0; i < array.size(); i++) {
            roles.add(array.get(i).textValue());
        }/*from  w ww.  ja v a2  s.c o m*/

        ACLEntry entry = new ACLEntry();
        entry.setPrincipal(principalId);
        entry.setAuthorities(roles);

        acl.add(principalId, entry);
    }

    return acl;
}

From source file:com.pros.jsontransform.expression.FunctionReplace.java

public static JsonNode evaluate(final JsonNode argsNode, final JsonNode valueNode,
        final ObjectTransformer transformer) throws ObjectTransformerException {
    ObjectNode resultNode = (ObjectNode) argsNode;
    resultNode.put("returnValue",
            transformValue(valueNode, transformer).replace(argsNode.path(ARGUMENT_WHAT).asText(),
                    transformArgument(argsNode.path(ARGUMENT_WITH), transformer).asText()));

    return resultNode.get("returnValue");
}

From source file:com.mirth.connect.client.ui.components.rsta.FindReplaceProperties.java

static FindReplaceProperties fromJSON(String findReplaceJSON) {
    List<String> findHistory = new ArrayList<String>();
    List<String> replaceHistory = new ArrayList<String>();
    Map<String, Boolean> optionsMap = new HashMap<String, Boolean>();

    if (StringUtils.isNotBlank(findReplaceJSON)) {
        try {//from w ww  .j a  va2 s. co  m
            ObjectMapper mapper = new ObjectMapper();
            ObjectNode rootNode = (ObjectNode) mapper.readTree(findReplaceJSON);

            ArrayNode findHistoryNode = (ArrayNode) rootNode.get("findHistory");
            for (Iterator<JsonNode> it = findHistoryNode.elements(); it.hasNext();) {
                findHistory.add(it.next().asText());
            }

            ArrayNode replaceHistoryNode = (ArrayNode) rootNode.get("replaceHistory");
            for (Iterator<JsonNode> it = replaceHistoryNode.elements(); it.hasNext();) {
                replaceHistory.add(it.next().asText());
            }

            ObjectNode optionsNode = (ObjectNode) rootNode.get("options");
            for (Iterator<Entry<String, JsonNode>> it = optionsNode.fields(); it.hasNext();) {
                Entry<String, JsonNode> entry = it.next();

                if (!entry.getValue().isNull()) {
                    optionsMap.put(entry.getKey(), entry.getValue().asBoolean());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return new FindReplaceProperties(findHistory, replaceHistory, optionsMap);
}

From source file:mobile.service.SelfInfoService.java

/**
 * ????/*from  ww w  . j  a  v a2  s  . co  m*/
 * 
 * @param jobExpArray
 * @return
 */
public static ServiceResult saveJobExp(ArrayNode jobExpArray) {
    ArrayNode newJobExpArray = jobExpArray.deepCopy();
    Iterator<JsonNode> elements = newJobExpArray.elements();
    while (elements.hasNext()) {
        ObjectNode next = (ObjectNode) elements.next();
        if (next.hasNonNull("endYear") && next.get("endYear").asText().equals("-1")) {
            next.put("endYear", "");
        }
    }

    ObjectNode jobExpNode = Json.newObject();
    jobExpNode.set("jobExp", newJobExpArray);
    ObjectNodeResult objectNodeResult = Expert.saveExpertByJson(Context.current().session(), jobExpNode);

    return ServiceResult.create(objectNodeResult);
}