How to compare two JsonNodes with Jackson?

You current code looks ok, the JsonNode class provides JsonNode.equals(Object) method for checking:

Equality for node objects is defined as full (deep) value equality.

Since version 2.6 there is also overloaded version which uses a custom comparator:

public boolean equals(Comparator<JsonNode> comparator, JsonNode other){
    return comparator.compare(this, other) == 0;
}

That's good enough to use JsonNode.equals:

Equality for node objects is defined as full (deep) value equality. This means that it is possible to compare complete JSON trees for equality by comparing equality of root nodes.

Maybe also add a null check as test != null