src/main/java/au/org/dcw/twitter/ingest/ui/TweetSanitiserUI.java
private void stripFields(final JsonNode root, final Map<String, Object> toKeep) {

        List<String> toRemove = Lists.newArrayList();

        final Iterator<String> fieldIterator = root.fieldNames();
        while (fieldIterator.hasNext()) {
            String field = fieldIterator.next();
            if (! toKeep.containsKey(field)) {
                toRemove.add(field);
            }
        }
        ((ObjectNode) root).remove(toRemove);

        for (String field: toKeep.keySet()) {
            Map<String, Object> value = (Map<String, Object>) toKeep.get(field);
            if (value != null && root.has(field)) {
                stripFields(root.get(field), value);
            }
        }
    }
/**
     * Strips unwanted fields directly from a {@link JsonNode} tree structure.
     *
     * @param root The root of the tree.
     * @param toKeep The fields to keep - i.e. remove the others.
     */
Strips unwanted fields directly from a  JsonNode tree structure.
@param root The root of the tree.
@param toKeep The fields to keep - i.e. remove the others.
Strips unwanted fields directly from a JsonNode tree structure . @param root The root of the tree . @param toKeep The fields to keep - i . e . remove the others .
private void stripFields(final JsonNode root, final Map<String, Object> toKeep) {
        List<String> toRemove = Lists.newArrayList();
        final Iterator<String> fieldIterator = root.fieldNames();
        while (fieldIterator.hasNext()) {
            String field = fieldIterator.next();
            if (! toKeep.containsKey(field)) {
                toRemove.add(field);
            }
        }
        ((ObjectNode) root).remove(toRemove);
        for (String field: toKeep.keySet()) {
            Map<String, Object> value = (Map<String, Object>) toKeep.get(field);
            if (value != null && root.has(field)) {
                stripFields(root.get(field), value);
            }
        }
    }
private void stripFields ( final JsonNode root , final Map < String , Object > toKeep ) { List < String > toRemove = Lists . newArrayList ( ) ; final Iterator < String > fieldIterator = root . fieldNames ( ) ; while ( fieldIterator . hasNext ( ) ) { String field = fieldIterator . next ( ) ; if ( ! toKeep . containsKey ( field ) ) { toRemove . add ( field ) ; } } ( ( ObjectNode ) root ) . remove ( toRemove ) ; for ( String field : toKeep . keySet ( ) ) { Map < String , Object > value = ( Map < String , Object > ) toKeep . get ( field ) ; if ( value != null && root . has ( field ) ) { stripFields ( root . get ( field ) , value ) ; } } }
Strips unwanted fields directly from a {@link JsonNode} tree structure.
Strips unwanted fields directly from a { @link JsonNode } tree structure .