Example usage for com.fasterxml.jackson.databind.node ArrayNode size

List of usage examples for com.fasterxml.jackson.databind.node ArrayNode size

Introduction

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

Prototype

public int size() 

Source Link

Usage

From source file:org.flowable.admin.service.engine.FormInstanceService.java

public JsonNode getFormInstanceFormFieldValues(ServerConfig serverConfig, String formInstanceId) {

    ObjectNode returnNode = null;/*from  w  w w. j av a2 s  .c  o  m*/

    try {
        returnNode = objectMapper.createObjectNode();

        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("formInstanceId", formInstanceId);

        URIBuilder builder = clientUtil.createUriBuilder("form/form-instance-model");
        HttpPost post = clientUtil.createPost(builder.toString(), serverConfig);
        post.setEntity(clientUtil.createStringEntity(requestNode.toString()));

        JsonNode resultNode = clientUtil.executeRequest(post, serverConfig);

        ArrayNode formFieldValues = objectMapper.createArrayNode();

        if (resultNode != null && resultNode.has("fields") && resultNode.get("fields").isArray()) {

            ArrayNode fieldsNode = (ArrayNode) resultNode.get("fields");
            for (JsonNode fieldNode : fieldsNode) {

                ObjectNode formFieldValue = objectMapper.createObjectNode();

                formFieldValue.set("id", fieldNode.get("id"));
                formFieldValue.set("name", fieldNode.get("name"));
                formFieldValue.set("type", fieldNode.get("type"));
                formFieldValue.set("value", fieldNode.get("value"));

                formFieldValues.add(formFieldValue);
            }
        }

        returnNode.put("size", formFieldValues.size());
        returnNode.put("total", formFieldValues.size());
        returnNode.set("data", formFieldValues);
    } catch (Exception ex) {
        throw new FlowableServiceException(ex.getMessage(), ex);
    }

    return returnNode;
}

From source file:com.unboundid.scim2.common.utils.JsonDiff.java

/**
 * Removes the value from an ArrayNode that matches the provided node.
 *
 * @param sourceValue The sourceValue node to match.
 * @param targetValues The ArrayNode containing the values to remove from.
 * @return The matching value that was removed or {@code null} if no matching
 *         value was found./*w  ww  .  j  a va 2s.  c  o  m*/
 */
private JsonNode removeMatchingValue(final JsonNode sourceValue, final ArrayNode targetValues) {
    if (sourceValue.isObject()) {
        // Find a target value that has the most fields in common with the source
        // and have identical values. Common fields that are also one of the
        // SCIM standard multi-value sub-attributes (ie. type, value, etc...) have
        // a higher weight when determining the best matching value.
        TreeMap<Integer, Integer> matchScoreToIndex = new TreeMap<Integer, Integer>();
        for (int i = 0; i < targetValues.size(); i++) {
            JsonNode targetValue = targetValues.get(i);
            if (targetValue.isObject()) {
                int matchScore = 0;
                Iterator<String> si = sourceValue.fieldNames();
                while (si.hasNext()) {
                    String field = si.next();
                    if (sourceValue.get(field).equals(targetValue.path(field))) {
                        if (field.equals("value") || field.equals("$ref")) {
                            // These fields have the highest chance of having unique values.
                            matchScore += 3;
                        } else if (field.equals("type") || field.equals("display")) {
                            // These fields should mostly be unique.
                            matchScore += 2;
                        } else if (field.equals("primary")) {
                            // This field will definitely not be unique.
                            matchScore += 0;
                        } else {
                            // Not one of the normative fields. Use the default weight.
                            matchScore += 1;
                        }
                    }
                }
                // Only consider the match if there is not already match with the same
                // score. This will prefer matches at the same index in the array.
                if (matchScore > 0 && !matchScoreToIndex.containsKey(matchScore)) {
                    matchScoreToIndex.put(matchScore, i);
                }
            }
        }
        if (!matchScoreToIndex.isEmpty()) {
            return targetValues.remove(matchScoreToIndex.lastEntry().getValue());
        }
    } else {
        // Find an exact match
        for (int i = 0; i < targetValues.size(); i++) {
            if (JsonUtils.compareTo(sourceValue, targetValues.get(i), null) == 0) {
                return targetValues.remove(i);
            }
        }
    }

    // Can't find a match at all.
    return null;
}

From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.ArraySliceExpressionEvaluator.java

private List<JRJsonNode> goAnywhereDown(JRJsonNode jrJsonNode) {
    List<JRJsonNode> result = new ArrayList<>();
    Deque<JRJsonNode> stack = new ArrayDeque<>();

    if (log.isDebugEnabled()) {
        log.debug("initial stack population with: " + jrJsonNode.getDataNode());
    }/*from w ww.ja  v  a  2 s .c  o  m*/

    // populate the stack initially
    stack.push(jrJsonNode);

    while (!stack.isEmpty()) {
        JRJsonNode stackNode = stack.pop();
        JsonNode stackDataNode = stackNode.getDataNode();

        addChildrenToStack(stackNode, stack);

        // process the current stack item
        if (stackDataNode.isArray()) {
            if (log.isDebugEnabled()) {
                log.debug("processing stack element: " + stackDataNode);
            }

            ArrayNode newNode = getEvaluationContext().getObjectMapper().createArrayNode();

            Integer start = getSliceStart(stackDataNode.size());
            if (start >= stackDataNode.size()) {
                continue;
            }

            Integer end = getSliceEnd(stackDataNode.size());
            if (end < 0) {
                continue;
            }

            for (int i = start; i < end; i++) {
                JRJsonNode nodeAtIndex = stackNode.createChild(stackDataNode.get(i));

                if (applyFilter(nodeAtIndex)) {
                    newNode.add(nodeAtIndex.getDataNode());
                }
            }

            if (newNode.size() > 0) {
                result.add(stackNode.createChild(newNode));
            }
        }
    }

    return result;
}

From source file:org.flowable.cmmn.editor.json.converter.CmmnJsonConverter.java

protected void readShapeInfo(JsonNode objectNode, Map<String, JsonNode> shapeMap,
        Map<String, JsonNode> sourceRefMap) {

    if (objectNode.get(EDITOR_CHILD_SHAPES) != null) {
        for (JsonNode jsonChildNode : objectNode.get(EDITOR_CHILD_SHAPES)) {

            String stencilId = CmmnJsonConverterUtil.getStencilId(jsonChildNode);
            if (!STENCIL_ASSOCIATION.equals(stencilId)) {

                String childShapeId = jsonChildNode.get(EDITOR_SHAPE_ID).asText();
                shapeMap.put(childShapeId, jsonChildNode);

                ArrayNode outgoingNode = (ArrayNode) jsonChildNode.get("outgoing");
                if (outgoingNode != null && outgoingNode.size() > 0) {
                    for (JsonNode outgoingChildNode : outgoingNode) {
                        JsonNode resourceNode = outgoingChildNode.get(EDITOR_SHAPE_ID);
                        if (resourceNode != null) {
                            sourceRefMap.put(resourceNode.asText(), jsonChildNode);
                        }/*from   w  w w .  j av a 2  s .c  o m*/
                    }
                }

                readShapeInfo(jsonChildNode, shapeMap, sourceRefMap);
            }
        }
    }
}

From source file:org.wrml.runtime.format.text.html.WrmldocFormatter.java

protected ObjectNode buildResourceNode(final ObjectMapper objectMapper, final Map<URI, ObjectNode> schemaNodes,
        final Map<URI, LinkRelation> linkRelationCache, final ApiNavigator apiNavigator,
        final Resource resource) {

    final Context context = getContext();
    final SchemaLoader schemaLoader = context.getSchemaLoader();
    final SyntaxLoader syntaxLoader = context.getSyntaxLoader();

    final ObjectNode resourceNode = objectMapper.createObjectNode();

    resourceNode.put(PropertyName.id.name(), syntaxLoader.formatSyntaxValue(resource.getResourceTemplateId()));
    resourceNode.put(PropertyName.pathSegment.name(), resource.getPathSegment());
    resourceNode.put(PropertyName.fullPath.name(), resource.getPathText());

    final String parentPathText = resource.getParentPathText();
    if (parentPathText != null) {
        resourceNode.put(PropertyName.parentPath.name(), parentPathText);
    }/*  ww  w  . j  a  v  a2s  . c  o m*/

    resourceNode.put(PropertyName.uriTemplate.name(), resource.getUriTemplate().getUriTemplateString());

    final URI defaultSchemaUri = resource.getDefaultSchemaUri();
    Prototype defaultPrototype = null;
    if (defaultSchemaUri != null) {
        final ObjectNode defaultSchemaNode = getSchemaNode(objectMapper, schemaNodes, defaultSchemaUri,
                schemaLoader);
        resourceNode.put(PropertyName.defaultSchema.name(), defaultSchemaNode);
        defaultPrototype = schemaLoader.getPrototype(defaultSchemaUri);
    }

    final ArrayNode referencesNode = buildReferencesArrayNode(objectMapper, schemaNodes, linkRelationCache,
            resource, defaultPrototype);
    if (referencesNode.size() > 0) {
        resourceNode.put(PropertyName.references.name(), referencesNode);
    }

    final ObjectNode linksNode = buildLinksNode(objectMapper, schemaNodes, linkRelationCache, apiNavigator,
            resource, defaultPrototype);
    if (linksNode.size() > 0) {
        resourceNode.put(PropertyName.links.name(), linksNode);
    }

    return resourceNode;
}

From source file:com.almende.eve.agent.google.GoogleCalendarAgent.java

/**
 * Get all events in given interval.//ww  w .  java  2  s  . c o m
 * 
 * @param timeMin
 *            start of the interval
 * @param timeMax
 *            end of the interval
 * @param calendarId
 *            optional calendar id. If not provided, the default calendar is
 *            used
 * @return the events
 * @throws Exception
 *             the exception
 */
@Override
public ArrayNode getEvents(@Optional @Name("timeMin") final String timeMin,
        @Optional @Name("timeMax") final String timeMax, @Optional @Name("calendarId") String calendarId)
        throws Exception {
    // initialize optional parameters
    if (calendarId == null) {
        calendarId = getState().get("email", String.class);
    }

    // built url with query parameters
    String url = CALENDAR_URI + calendarId + "/events";
    final Map<String, String> params = new HashMap<String, String>();
    if (timeMin != null) {
        params.put("timeMin", new DateTime(timeMin).toString());
    }
    if (timeMax != null) {
        params.put("timeMax", new DateTime(timeMax).toString());
    }
    // Set singleEvents=true to expand recurring events into instances
    params.put("singleEvents", "true");
    url = HttpUtil.appendQueryParams(url, params);

    // perform GET request
    final Map<String, String> headers = getAuthorizationHeaders();
    final String resp = HttpUtil.get(url, headers);
    final ObjectMapper mapper = JOM.getInstance();
    final ObjectNode json = mapper.readValue(resp, ObjectNode.class);

    // check for errors
    if (json.has("error")) {
        final ObjectNode error = (ObjectNode) json.get("error");
        throw new JSONRPCException(error);
    }

    // get items from the response
    ArrayNode items = null;
    if (json.has("items")) {
        items = (ArrayNode) json.get("items");

        // convert from Google to Eve event
        for (int i = 0; i < items.size(); i++) {
            final ObjectNode item = (ObjectNode) items.get(i);
            toEveEvent(item);
        }
    } else {
        items = JOM.createArrayNode();
    }

    return items;
}

From source file:org.walkmod.conf.providers.yml.RemoveProvidersYMLAction.java

@Override
public void doAction(JsonNode node) throws Exception {
    HashSet<String> providerSet = new HashSet<String>();
    for (String elem : providers) {
        String[] partsType = elem.split(":");
        if (partsType.length == 1) {
            elem = "org.walkmod:walkmod-" + elem + "-plugin:" + elem;
        }/*from   w  ww  . ja v  a  2s  .c  om*/
        if (partsType.length != 3 && partsType.length != 1) {
            throw new TransformerException("Invalid conf-provider");
        }
        providerSet.add(elem);
    }
    if (node.has("conf-providers")) {
        JsonNode aux = node.get("conf-providers");
        if (aux.isArray()) {
            ArrayNode providersList = (ArrayNode) node.get("conf-providers");
            Iterator<JsonNode> it = providersList.iterator();
            ArrayNode newProvidersList = new ArrayNode(provider.getObjectMapper().getNodeFactory());
            while (it.hasNext()) {
                JsonNode next = it.next();
                if (next.isObject()) {
                    String type = next.get("type").asText();
                    String[] parts = type.split(":");
                    if (parts.length == 1) {
                        type = "org.walkmod:walkmod-" + type + "-plugin:" + type;
                    } else if (parts.length != 3) {
                        throw new TransformerException("Invalid conf-provider");
                    }
                    if (!providerSet.contains(type)) {
                        newProvidersList.add(next);
                    }
                }
            }
            ObjectNode oNode = (ObjectNode) node;
            if (newProvidersList.size() > 0) {
                oNode.set("conf-providers", newProvidersList);
            } else {
                oNode.remove("conf-providers");
            }
            provider.write(node);
        }
    }

}

From source file:org.flowable.cmmn.editor.json.converter.CmmnJsonConverter.java

public CmmnModel convertToCmmnModel(JsonNode modelNode, Map<String, String> formKeyMap,
        Map<String, String> decisionTableKeyMap, Map<String, String> caseModelKeyMap,
        Map<String, String> processModelKeyMap) {

    CmmnModel cmmnModel = new CmmnModel();
    CmmnModelIdHelper cmmnModelIdHelper = new CmmnModelIdHelper();

    cmmnModel.setTargetNamespace("http://flowable.org/test");
    Map<String, JsonNode> shapeMap = new HashMap<>();
    Map<String, JsonNode> sourceRefMap = new HashMap<>();
    Map<String, JsonNode> edgeMap = new HashMap<>();
    Map<String, List<JsonNode>> sourceAndTargetMap = new HashMap<>();

    readShapeInfo(modelNode, shapeMap, sourceRefMap);
    filterAllEdges(modelNode, edgeMap, sourceAndTargetMap, shapeMap, sourceRefMap);

    ArrayNode shapesArrayNode = (ArrayNode) modelNode.get(EDITOR_CHILD_SHAPES);

    if (shapesArrayNode == null || shapesArrayNode.size() == 0) {
        return cmmnModel;
    }// w w w . j a  v a  2 s  . com

    Case caseModel = new Case();
    cmmnModel.getCases().add(caseModel);
    caseModel.setId(CmmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_CASE_ID, modelNode));
    caseModel.setName(CmmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, modelNode));
    caseModel.setInitiatorVariableName(
            CmmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_CASE_INITIATOR_VARIABLE_NAME, modelNode));
    if (StringUtils.isEmpty(caseModel.getInitiatorVariableName())) {
        caseModel.setInitiatorVariableName("initiator");
    }

    String namespace = CmmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_CASE_NAMESPACE, modelNode);
    if (StringUtils.isNotEmpty(namespace)) {
        cmmnModel.setTargetNamespace(namespace);
    }
    caseModel.setDocumentation(
            CmmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_DOCUMENTATION, modelNode));

    JsonNode planModelShape = shapesArrayNode.get(0);

    JsonNode planModelShapesArray = planModelShape.get(EDITOR_CHILD_SHAPES);
    Stage planModelStage = new Stage();
    planModelStage.setId(CmmnJsonConverterUtil.getElementId(planModelShape));
    planModelStage.setName(CmmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, planModelShape));
    planModelStage.setPlanModel(true);

    caseModel.setPlanModel(planModelStage);

    processJsonElements(planModelShapesArray, modelNode, planModelStage, shapeMap, formKeyMap,
            decisionTableKeyMap, caseModelKeyMap, processModelKeyMap, cmmnModel, cmmnModelIdHelper);

    List<String> planModelExitCriteriaRefs = new ArrayList<>();
    for (JsonNode shapeNode : shapesArrayNode) {
        // associations are now all on root level
        if (STENCIL_ASSOCIATION.equalsIgnoreCase(CmmnJsonConverterUtil.getStencilId(shapeNode))) {
            AssociationJsonConverter associationConverter = new AssociationJsonConverter();
            Association association = associationConverter.convertJsonToElement(shapeNode, modelNode, this,
                    planModelStage, shapeMap, cmmnModel, cmmnModelIdHelper);
            cmmnModel.addAssociation(association);

            // exit criteria for the plan model are on the root level
        } else if (STENCIL_EXIT_CRITERION.equalsIgnoreCase(CmmnJsonConverterUtil.getStencilId(shapeNode))) {
            JsonNode resourceNode = shapeNode.get(EDITOR_SHAPE_ID);
            if (resourceNode != null) {
                planModelExitCriteriaRefs.add(resourceNode.asText());
                CriterionJsonConverter criterionJsonConverter = new CriterionJsonConverter();
                criterionJsonConverter.convertJsonToElement(shapeNode, modelNode, this, planModelStage,
                        shapeMap, cmmnModel, cmmnModelIdHelper);
            }
        }
    }

    readShapeDI(modelNode, 0, 0, cmmnModel);
    readEdgeDI(edgeMap, sourceAndTargetMap, cmmnModel);

    // post handling of process elements
    Map<String, List<Association>> associationMap = postProcessAssociations(cmmnModel);
    postProcessElements(planModelStage, planModelStage.getPlanItems(), edgeMap, associationMap, cmmnModel,
            cmmnModelIdHelper);

    // Create sentries for exit criteria on plan model
    createSentryParts(planModelExitCriteriaRefs, planModelStage, associationMap, cmmnModel, cmmnModelIdHelper,
            null, planModelStage);

    return cmmnModel;
}

From source file:org.activiti.editor.language.json.converter.BpmnJsonConverter.java

private void readShapeDI(JsonNode objectNode, double parentX, double parentY, Map<String, JsonNode> shapeMap,
        Map<String, JsonNode> sourceRefMap, BpmnModel bpmnModel) {

    if (objectNode.get(EDITOR_CHILD_SHAPES) != null) {
        for (JsonNode jsonChildNode : objectNode.get(EDITOR_CHILD_SHAPES)) {

            String stencilId = BpmnJsonConverterUtil.getStencilId(jsonChildNode);
            if (STENCIL_SEQUENCE_FLOW.equals(stencilId) == false) {

                GraphicInfo graphicInfo = new GraphicInfo();

                JsonNode boundsNode = jsonChildNode.get(EDITOR_BOUNDS);
                ObjectNode upperLeftNode = (ObjectNode) boundsNode.get(EDITOR_BOUNDS_UPPER_LEFT);
                graphicInfo.setX(upperLeftNode.get(EDITOR_BOUNDS_X).asDouble() + parentX);
                graphicInfo.setY(upperLeftNode.get(EDITOR_BOUNDS_Y).asDouble() + parentY);

                ObjectNode lowerRightNode = (ObjectNode) boundsNode.get(EDITOR_BOUNDS_LOWER_RIGHT);
                graphicInfo.setWidth(//w w  w.j a va  2 s .c o  m
                        lowerRightNode.get(EDITOR_BOUNDS_X).asDouble() - graphicInfo.getX() + parentX);
                graphicInfo.setHeight(
                        lowerRightNode.get(EDITOR_BOUNDS_Y).asDouble() - graphicInfo.getY() + parentY);

                String childShapeId = jsonChildNode.get(EDITOR_SHAPE_ID).asText();
                bpmnModel.addGraphicInfo(BpmnJsonConverterUtil.getElementId(jsonChildNode), graphicInfo);

                shapeMap.put(childShapeId, jsonChildNode);

                ArrayNode outgoingNode = (ArrayNode) jsonChildNode.get("outgoing");
                if (outgoingNode != null && outgoingNode.size() > 0) {
                    for (JsonNode outgoingChildNode : outgoingNode) {
                        JsonNode resourceNode = outgoingChildNode.get(EDITOR_SHAPE_ID);
                        if (resourceNode != null) {
                            sourceRefMap.put(resourceNode.asText(), jsonChildNode);
                        }
                    }
                }

                readShapeDI(jsonChildNode, graphicInfo.getX(), graphicInfo.getY(), shapeMap, sourceRefMap,
                        bpmnModel);
            }
        }
    }
}

From source file:io.apiman.test.common.json.JsonCompare.java

/**
 * Asserts that the JSON document matches what we expected.
 * @param expectedJson/* ww w  . j a v a 2 s . c o  m*/
 * @param actualJson
 */
public void assertJson(JsonNode expectedJson, JsonNode actualJson) {
    if (expectedJson instanceof ArrayNode) {
        JsonNode actualValue = actualJson;
        ArrayNode expectedArray = (ArrayNode) expectedJson;
        Assert.assertEquals(
                message("Expected JSON array but found non-array [{0}] instead.",
                        actualValue.getClass().getSimpleName()),
                expectedJson.getClass(), actualValue.getClass());
        ArrayNode actualArray = (ArrayNode) actualValue;
        Assert.assertEquals(message("Array size mismatch."), expectedArray.size(), actualArray.size());

        JsonNode[] expected = new JsonNode[expectedArray.size()];
        JsonNode[] actual = new JsonNode[actualArray.size()];
        for (int idx = 0; idx < expected.length; idx++) {
            expected[idx] = expectedArray.get(idx);
            actual[idx] = actualArray.get(idx);
        }
        // If strict ordering is disabled, then sort both arrays
        if (getArrayOrdering() == JsonArrayOrderingType.any) {
            Comparator<? super JsonNode> comparator = new Comparator<JsonNode>() {
                @Override
                public int compare(JsonNode o1, JsonNode o2) {
                    String str1 = o1.asText();
                    String str2 = o2.asText();
                    if (o1.isObject() && o2.isObject()) {
                        // Try name (PermissionBean only)
                        JsonNode o1NameNode = o1.get("name");
                        JsonNode o2NameNode = o2.get("name");
                        if (o1NameNode != null && o2NameNode != null) {
                            str1 = o1NameNode.asText();
                            str2 = o2NameNode.asText();
                        }

                        // Try username (UserBean only)
                        JsonNode o1UsernameNode = o1.get("username");
                        JsonNode o2UsernameNode = o2.get("username");
                        if (o1UsernameNode != null && o2UsernameNode != null) {
                            str1 = o1UsernameNode.asText();
                            str2 = o2UsernameNode.asText();
                        }

                        // Try version (*VersionBeans)
                        JsonNode o1VersionNode = o1.get("version");
                        JsonNode o2VersionNode = o2.get("version");
                        if (o1VersionNode != null && o2VersionNode != null) {
                            str1 = o1VersionNode.asText();
                            str2 = o2VersionNode.asText();
                        }

                        // Try OrganizationBean.id (Orgs)
                        JsonNode o1OrgNode = o1.get("OrganizationBean");
                        JsonNode o2OrgNode = o2.get("OrganizationBean");
                        if (o1OrgNode != null && o2OrgNode != null) {
                            str1 = o1OrgNode.get("id").asText();
                            str2 = o2OrgNode.get("id").asText();
                        }

                        // Try ClientBean.id (Orgs)
                        JsonNode o1ClientNode = o1.get("ClientBean");
                        JsonNode o2ClientNode = o2.get("ClientBean");
                        if (o1ClientNode != null && o2ClientNode != null) {
                            str1 = o1ClientNode.get("id").asText();
                            str2 = o2ClientNode.get("id").asText();
                        }

                        // Try PlanBean.id (Orgs)
                        JsonNode o1PlanNode = o1.get("PlanBean");
                        JsonNode o2PlanNode = o2.get("PlanBean");
                        if (o1PlanNode != null && o2PlanNode != null) {
                            str1 = o1PlanNode.get("id").asText();
                            str2 = o2PlanNode.get("id").asText();
                        }

                        // Try ApiBean.id (Orgs)
                        JsonNode o1ApiNode = o1.get("ApiBean");
                        JsonNode o2ApiNode = o2.get("ApiBean");
                        if (o1ApiNode != null && o2ApiNode != null) {
                            str1 = o1ApiNode.get("id").asText();
                            str2 = o2ApiNode.get("id").asText();
                        }

                        // Try Id (all other beans)
                        JsonNode o1IdNode = o1.get("id");
                        JsonNode o2IdNode = o2.get("id");
                        if (o1IdNode != null && o2IdNode != null) {
                            if (o1IdNode.isNumber()) {
                                return new Long(o1IdNode.asLong()).compareTo(o2IdNode.asLong());
                            }
                            str1 = o1IdNode.asText();
                            str2 = o2IdNode.asText();
                        }
                    }
                    int cmp = str1.compareTo(str2);
                    if (cmp == 0)
                        cmp = 1;
                    return cmp;
                }
            };
            Arrays.sort(expected, comparator);
            Arrays.sort(actual, comparator);
        }
        for (int idx = 0; idx < expected.length; idx++) {
            currentPath.push(idx);
            assertJson(expected[idx], actual[idx]);
            currentPath.pop();
        }
    } else {
        Iterator<Entry<String, JsonNode>> fields = expectedJson.fields();
        Set<String> expectedFieldNames = new HashSet<>();
        while (fields.hasNext()) {
            Entry<String, JsonNode> entry = fields.next();
            String expectedFieldName = entry.getKey();
            expectedFieldNames.add(expectedFieldName);
            JsonNode expectedValue = entry.getValue();
            currentPath.push(expectedFieldName);
            if (expectedValue instanceof TextNode) {
                TextNode tn = (TextNode) expectedValue;
                String expected = tn.textValue();
                JsonNode actualValue = actualJson.get(expectedFieldName);

                if (isIgnoreCase()) {
                    expected = expected.toLowerCase();
                    if (actualValue == null) {
                        actualValue = actualJson.get(expectedFieldName.toLowerCase());
                    }
                }

                Assert.assertNotNull(
                        message("Expected JSON text field \"{0}\" with value \"{1}\" but was not found.",
                                expectedFieldName, expected),
                        actualValue);
                Assert.assertEquals(message(
                        "Expected JSON text field \"{0}\" with value \"{1}\" but found non-text [{2}] field with that name instead.",
                        expectedFieldName, expected, actualValue.getClass().getSimpleName()), TextNode.class,
                        actualValue.getClass());
                String actual = ((TextNode) actualValue).textValue();

                if (isIgnoreCase()) {
                    if (actual != null) {
                        actual = actual.toLowerCase();
                    }
                }

                if (!expected.equals("*")) {
                    Assert.assertEquals(message("Value mismatch for text field \"{0}\".", expectedFieldName),
                            expected, actual);
                }
            } else if (expectedValue.isNumber()) {
                NumericNode numeric = (NumericNode) expectedValue;
                Number expected = numeric.numberValue();
                JsonNode actualValue = actualJson.get(expectedFieldName);
                try {
                    Assert.assertNotNull(
                            message("Expected JSON numeric field \"{0}\" with value \"{1}\" but was not found.",
                                    expectedFieldName, expected),
                            actualValue);
                } catch (Error e) {
                    throw e;
                }
                Assert.assertTrue(message(
                        "Expected JSON numeric field \"{0}\" with value \"{1}\" but found non-numeric [{2}] field with that name instead.",
                        expectedFieldName, expected, actualValue.getClass().getSimpleName()),
                        actualValue.isNumber());
                Number actual = ((NumericNode) actualValue).numberValue();
                if (!"id".equals(expectedFieldName) || isCompareNumericIds()) {
                    Assert.assertEquals(message("Value mismatch for numeric field \"{0}\".", expectedFieldName),
                            expected, actual);
                }
            } else if (expectedValue instanceof BooleanNode) {
                BooleanNode bool = (BooleanNode) expectedValue;
                Boolean expected = bool.booleanValue();
                JsonNode actualValue = actualJson.get(expectedFieldName);
                Assert.assertNotNull(
                        message("Expected JSON boolean field \"{0}\" with value \"{1}\" but was not found.",
                                expectedFieldName, expected),
                        actualValue);
                Assert.assertEquals(message(
                        "Expected JSON boolean field \"{0}\" with value \"{1}\" but found non-boolean [{2}] field with that name instead.",
                        expectedFieldName, expected, actualValue.getClass().getSimpleName()),
                        expectedValue.getClass(), actualValue.getClass());
                Boolean actual = ((BooleanNode) actualValue).booleanValue();
                Assert.assertEquals(message("Value mismatch for boolean field \"{0}\".", expectedFieldName),
                        expected, actual);
            } else if (expectedValue instanceof ObjectNode) {
                JsonNode actualValue = actualJson.get(expectedFieldName);
                Assert.assertNotNull(
                        message("Expected parent JSON field \"{0}\" but was not found.", expectedFieldName),
                        actualValue);
                Assert.assertEquals(
                        message("Expected parent JSON field \"{0}\" but found field of type \"{1}\".",
                                expectedFieldName, actualValue.getClass().getSimpleName()),
                        ObjectNode.class, actualValue.getClass());
                assertJson(expectedValue, actualValue);
            } else if (expectedValue instanceof ArrayNode) {
                JsonNode actualValue = actualJson.get(expectedFieldName);
                Assert.assertNotNull(
                        message("Expected JSON array field \"{0}\" but was not found.", expectedFieldName),
                        actualValue);
                ArrayNode expectedArray = (ArrayNode) expectedValue;
                Assert.assertEquals(message(
                        "Expected JSON array field \"{0}\" but found non-array [{1}] field with that name instead.",
                        expectedFieldName, actualValue.getClass().getSimpleName()), expectedValue.getClass(),
                        actualValue.getClass());
                ArrayNode actualArray = (ArrayNode) actualValue;
                Assert.assertEquals(message("Field \"{0}\" array size mismatch.", expectedFieldName),
                        expectedArray.size(), actualArray.size());
                assertJson(expectedArray, actualArray);
            } else if (expectedValue instanceof NullNode) {
                JsonNode actualValue = actualJson.get(expectedFieldName);
                Assert.assertNotNull(
                        message("Expected Null JSON field \"{0}\" but was not found.", expectedFieldName),
                        actualValue);
                Assert.assertEquals(
                        message("Expected Null JSON field \"{0}\" but found field of type \"{0}\".",
                                expectedFieldName, actualValue.getClass().getSimpleName()),
                        NullNode.class, actualValue.getClass());
            } else {
                Assert.fail(message("Unsupported field type: {0}", expectedValue.getClass().getSimpleName()));
            }
            currentPath.pop();
        }

        if (getMissingField() == JsonMissingFieldType.fail) {
            Set<String> actualFieldNames = new HashSet();
            Iterator<String> names = actualJson.fieldNames();
            while (names.hasNext()) {
                actualFieldNames.add(names.next());
            }
            actualFieldNames.removeAll(expectedFieldNames);
            Assert.assertTrue(message("Found unexpected fields: {0}", StringUtils.join(actualFieldNames, ", ")),
                    actualFieldNames.isEmpty());
        }
    }
}