public static ObjectNode cleanProperties()

in streams-util/src/main/java/org/apache/streams/util/PropertyUtil.java [148:178]


  public static ObjectNode cleanProperties(ObjectMapper mapper, ObjectNode content) {

    ObjectNode cleaned = mapper.createObjectNode();

    Iterator<Map.Entry<String, JsonNode>> fields = content.fields();
    for ( ; fields.hasNext(); ) {
      Map.Entry<String, JsonNode> field = fields.next();
      String fieldId = field.getKey();
      if( field.getValue() != null && !field.getValue().getNodeType().equals(JsonNodeType.NULL)) {
        if( field.getValue().getNodeType().equals(JsonNodeType.OBJECT)) {
          ObjectNode clean = cleanProperties(mapper, field.getValue().deepCopy());
          if( clean != null && clean.size() > 0 ) {
            cleaned.put(fieldId, clean);
          }
        } else if ( field.getValue().getNodeType().equals(JsonNodeType.ARRAY)) {
          ArrayNode clean = cleanArray((ArrayNode)field.getValue());
          if( clean != null && clean.size() > 0 ) {
            cleaned.put(fieldId, clean);
          }
        } else if ( field.getValue().getNodeType().equals(JsonNodeType.STRING)) {
          String value = content.get(fieldId).asText();
          if( value != null && StringUtils.isNotBlank(value)) {
            cleaned.put(fieldId, value);
          }
        } else {
          cleaned.put(fieldId, field.getValue());
        }
      }
    }
    return cleaned;
  }