Class JSONReader

java.lang.Object
com.marswars.util.JSONReader
Direct Known Subclasses:
ConstantsLoader, MWPreferences

public class JSONReader extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.fasterxml.jackson.databind.ObjectMapper
     
    protected com.fasterxml.jackson.databind.JsonNode
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static ArrayList<String>
    getChildren(com.fasterxml.jackson.databind.JsonNode parent)
     
    protected void
    loadJson(String json_file)
     
    protected void
    loadJson(Path json_file)
    Loads JSON content from a specific file into a JSON tree for parsing
    protected com.fasterxml.jackson.databind.JsonNode
    searchArrayForPair(com.fasterxml.jackson.databind.JsonNode starting, String child_key, String child_value)
    Searches through a JSON array to find a specific key value pair
    protected static com.fasterxml.jackson.databind.JsonNode
    walkTree(com.fasterxml.jackson.databind.JsonNode starting, String... path_steps)
    Walks the JSON tree down to a specific node

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • root_node_

      protected com.fasterxml.jackson.databind.JsonNode root_node_
    • mapper_

      protected com.fasterxml.jackson.databind.ObjectMapper mapper_
  • Constructor Details

    • JSONReader

      public JSONReader()
  • Method Details

    • loadJson

      protected void loadJson(String json_file) throws IOException
      Throws:
      IOException
    • loadJson

      protected void loadJson(Path json_file) throws IOException
      Loads JSON content from a specific file into a JSON tree for parsing
      Parameters:
      json_file -
      Throws:
      IOException
    • searchArrayForPair

      protected com.fasterxml.jackson.databind.JsonNode searchArrayForPair(com.fasterxml.jackson.databind.JsonNode starting, String child_key, String child_value) throws JSONReader.ConstantParseError
      Searches through a JSON array to find a specific key value pair
      Parameters:
      starting - the starting json node to search from
      child_key - the primary key to look for
      child_value - the value of the primary key
      Returns:
      the node that contains child_key with the value of child_value
      Throws:
      JSONReader.ConstantParseError - when node is not an array or child_key and value cannot be found
    • walkTree

      protected static com.fasterxml.jackson.databind.JsonNode walkTree(com.fasterxml.jackson.databind.JsonNode starting, String... path_steps)
      Walks the JSON tree down to a specific node
      Parameters:
      path_steps - a list of path steps to take along the way
      Returns:
      the resulting node at the end of walking
    • getChildren

      protected static ArrayList<String> getChildren(com.fasterxml.jackson.databind.JsonNode parent)