Package com.clumd.projects.javajson.api
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 Summary
Modifier and Type Method Description static Jsonparse(JsonGenerator jsonable)A pass-through method to convert any object marked as capable of converting itself to JSON, into the JSON equivalent.static Jsonparse(String jsonAsString)Parse a single JSON object from String.static Jsonparse(String[] jsonAsStringArray)Parse a static array of strings into a single JSON object.static Jsonparse(Collection<String> jsonAsStringCollection)Parse a collection of strings into a single JSON object.static List<Json>parseMultipleJSONables(Collection<JsonGenerator> multipleJsonAsGenerators)Parse a collection of Java Objects marked as capable of converting themselves to JSON into a multiple JSON objects.static Set<Json>parseMultipleJSONablesForDistinct(Collection<JsonGenerator> multipleJsonAsGenerators)The same asparseMultipleJSONables(Collection), but any duplicates will be filtered out.static List<Json>parseMultipleStrings(Collection<String> multipleJsonAsStrings)Parse a collection of strings into a multiple JSON objects.static Set<Json>parseMultipleStringsForDistinct(Collection<String> multipleJsonAsStrings)The same asparseMultipleStrings(Collection), but any duplicates will be filtered out.
-
Method Details
-
parse
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
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
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
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 JsonExceptionParse 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 JsonExceptionParse 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 ownJsonGenerator.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 JsonExceptionThe same asparseMultipleStrings(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 JsonExceptionThe same asparseMultipleJSONables(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.
-