public Tree parseTreeV1() {
    final String json = query.getContent();
    if (json == null || json.isEmpty()) {
      throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
          "Missing message content",
          "Supply valid JSON formatted data in the body of your request");
    }
    try {
      final HashMap<String, String> properties = 
        JSON.parseToObject(json, TR_HASH_MAP);
      
      final Tree tree = new Tree();
      for (Map.Entry<String, String> entry : properties.entrySet()) {
        // skip nulls, empty is fine, but nulls are not welcome here
        if (entry.getValue() == null) {
          continue;
        }
        
        if (entry.getKey().toLowerCase().equals("treeid")) {
          tree.setTreeId(Integer.parseInt(entry.getValue()));
        } else if (entry.getKey().toLowerCase().equals("name")) {
          tree.setName(entry.getValue());
        } else if (entry.getKey().toLowerCase().equals("description")) {
          tree.setDescription(entry.getValue());
        } else if (entry.getKey().toLowerCase().equals("notes")) {
          tree.setNotes(entry.getValue());
        } else if (entry.getKey().toLowerCase().equals("enabled")) {
          if (entry.getValue().toLowerCase().equals("true")) {
            tree.setEnabled(true);
          } else {
            tree.setEnabled(false);
          }
        } else if (entry.getKey().toLowerCase().equals("strictmatch")) {
          if (entry.getValue().toLowerCase().equals("true")) {
            tree.setStrictMatch(true);
          } else {
            tree.setStrictMatch(false);
          }
        } else if (entry.getKey().toLowerCase().equals("storefailures")) {
          if (entry.getValue().toLowerCase().equals("true")) {
            tree.setStoreFailures(true);
          } else {
            tree.setStoreFailures(false);
          }
        }
      }
      return tree;
    } catch (NumberFormatException nfe) {
      throw new BadRequestException("Unable to parse 'tree' value");
    } catch (IllegalArgumentException iae) {
      throw new BadRequestException("Unable to parse the given JSON", iae);
    }
  }
public Tree parseTreeV1 ( ) { final String json = query . getContent ( ) ; if ( json == null || json . isEmpty ( ) ) { throw new BadRequestException ( HttpResponseStatus . BAD_REQUEST , "Missing message content" , "Supply valid JSON formatted data in the body of your request" ) ; } try { final HashMap < String , String > properties = JSON . parseToObject ( json , TR_HASH_MAP ) ; final Tree tree = new Tree ( ) ; for ( Map . Entry < String , String > entry : properties . entrySet ( ) ) { if ( entry . getValue ( ) == null ) { continue ; } if ( entry . getKey ( ) . toLowerCase ( ) . equals ( "treeid" ) ) { tree . setTreeId ( Integer . parseInt ( entry . getValue ( ) ) ) ; } else if ( entry . getKey ( ) . toLowerCase ( ) . equals ( "name" ) ) { tree . setName ( entry . getValue ( ) ) ; } else if ( entry . getKey ( ) . toLowerCase ( ) . equals ( "description" ) ) { tree . setDescription ( entry . getValue ( ) ) ; } else if ( entry . getKey ( ) . toLowerCase ( ) . equals ( "notes" ) ) { tree . setNotes ( entry . getValue ( ) ) ; } else if ( entry . getKey ( ) . toLowerCase ( ) . equals ( "enabled" ) ) { if ( entry . getValue ( ) . toLowerCase ( ) . equals ( "true" ) ) { tree . setEnabled ( true ) ; } else { tree . setEnabled ( false ) ; } } else if ( entry . getKey ( ) . toLowerCase ( ) . equals ( "strictmatch" ) ) { if ( entry . getValue ( ) . toLowerCase ( ) . equals ( "true" ) ) { tree . setStrictMatch ( true ) ; } else { tree . setStrictMatch ( false ) ; } } else if ( entry . getKey ( ) . toLowerCase ( ) . equals ( "storefailures" ) ) { if ( entry . getValue ( ) . toLowerCase ( ) . equals ( "true" ) ) { tree . setStoreFailures ( true ) ; } else { tree . setStoreFailures ( false ) ; } } } return tree ; } catch ( NumberFormatException nfe ) { throw new BadRequestException ( "Unable to parse 'tree' value" ) ; } catch ( IllegalArgumentException iae ) { throw new BadRequestException ( "Unable to parse the given JSON" , iae ) ; } }
Parses a single Tree object
<b>Note:</b> Incoming data is a hash map of strings instead of directly
deserializing to a tree. We do it this way because we don't want users
messing with the timestamp fields.
@return A parsed Tree
@throws JSONException if parsing failed
@throws BadRequestException if the content was missing or parsing failed