Class JsonParser

java.lang.Object
com.clumd.projects.javajson.api.JsonParser

public final class JsonParser
extends Object
A default static utility class for constructing JSON objects from various forms of String input.
  • Method Details

    • parse

      public static Json parse​(String jsonAsString) throws JsonException
      Parse a single JSON object from String.
      Parameters:
      jsonAsString - The JSON object in string form.
      Returns:
      The JSON object in Java-JSON form.
      Throws:
      JsonException - Thrown if there is a problem with the input.
    • parse

      public static Json parse​(Collection<String> jsonAsStringCollection) throws JsonException
      Parse a collection of strings into a single JSON object.
      Parameters:
      jsonAsStringCollection - The JSON object spread out across a collection of strings.
      Returns:
      The JSON object in Java-JSON form.
      Throws:
      JsonException - Thrown if there is a problem with the input.
    • parse

      public static Json parse​(String[] jsonAsStringArray) throws JsonException
      Parse a static array of strings into a single JSON object.
      Parameters:
      jsonAsStringArray - The JSON object spread out across a static array of strings.
      Returns:
      The JSON object in Java-JSON form.
      Throws:
      JsonException - Thrown if there is a problem with the input.
    • parse

      public static Json parse​(JsonGenerator jsonable) throws JsonException
      A pass-through method to convert any object marked as capable of converting itself to JSON, into the JSON equivalent.
      Parameters:
      jsonable - The Java object declaring itself as possible to convert to JSON.
      Returns:
      The JSON object in Java-JSON form.
      Throws:
      JsonException - Thrown if there is a problem with the input.
    • parseMultipleStrings

      public static List<Json> parseMultipleStrings​(Collection<String> multipleJsonAsStrings) throws JsonException
      Parse a collection of strings into a multiple JSON objects. Each string in the collection will be treated as it's own JSON object.
      Parameters:
      multipleJsonAsStrings - A collection of JSON objects in string form.
      Returns:
      The JSON objects in Java-JSON form.
      Throws:
      JsonException - Thrown if there is a problem with the input.
    • parseMultipleJSONables

      public static List<Json> parseMultipleJSONables​(Collection<JsonGenerator> multipleJsonAsGenerators) throws JsonException
      Parse a collection of Java Objects marked as capable of converting themselves to JSON into a multiple JSON objects. Each Java object in the collection will be passed through to its own JsonGenerator.convertToJSON() method.
      Parameters:
      multipleJsonAsGenerators - The collection of Java objects declaring themselves as supporting a conversion to JSON.
      Returns:
      The JSON objects in Java-JSON form.
      Throws:
      JsonException - Thrown if there is a problem with the input.
    • parseMultipleStringsForDistinct

      public static Set<Json> parseMultipleStringsForDistinct​(Collection<String> multipleJsonAsStrings) throws JsonException
      The same as parseMultipleStrings(Collection), but any duplicates will be filtered out.
      Parameters:
      multipleJsonAsStrings - A collection of JSON objects in string form, containing potential duplicates.
      Returns:
      A Set, of unique JSON objects converted from the input collection.
      Throws:
      JsonException - Thrown if there was a problem during the conversion process of the Java to JSON.
    • parseMultipleJSONablesForDistinct

      public static Set<Json> parseMultipleJSONablesForDistinct​(Collection<JsonGenerator> multipleJsonAsGenerators) throws JsonException
      The same as parseMultipleJSONables(Collection), but any duplicates will be filtered out.
      Parameters:
      multipleJsonAsGenerators - A collection of JSON objects declaring themselves as supporting a conversion to JSON, containing potential duplicates.
      Returns:
      A Set, of unique JSON objects converted from the input collection.
      Throws:
      JsonException - Thrown if there was a problem during the conversion process of the Java to JSON.