public final class JsonMethods extends Object
Constructor and Description |
---|
JsonMethods() |
Modifier and Type | Method and Description |
---|---|
static GloopCursor |
getInputCursorFromFile(String filename,
String encoding,
List<String> jsonNodeNames,
GloopExecutionContext context)
Parse a large JSON file.
|
static GloopCursor |
getInputCursorFromInputStream(InputStream inputStream,
String encoding,
List<String> jsonNodeNames,
GloopExecutionContext context)
Parse a large JSON stream.
|
static String |
gloopObjectToJsonString(GloopObject gloopObject)
Marshal a Gloop object to a JSON string.
|
static String |
gloopObjectToJsonString(GloopObject gloopObject,
boolean includeRoot,
boolean includeNulls)
Marshal a Gloop object to a JSON string.
|
static GloopObject |
inputStreamToGloopObject(InputStream jsonInputStream)
Unmarshal a stream containing JSON data to a Gloop object.
|
static GloopObject |
jsonStringToGloopObject(String jsonString)
Unmarshal a JSON string into a Gloop object.
|
static GloopModel |
openJsonOutputCursor(boolean prettyPrint,
boolean printStartDocumentBrace,
boolean printCommaAtStart,
boolean printStartArrayBracket,
boolean printEndArrayBracket,
boolean printEndDocumentBrace,
String name,
String indent,
boolean closeDestination,
Object destination,
GloopExecutionContext context)
Open a cursor for writing large amounts of JSON data.
|
static void |
printJson(IndentPrinter printer,
GloopObject gloopObject,
boolean includeNulls,
boolean includeRoot,
boolean pretty)
Marshal a Gloop object to a printer.
|
static GloopObject |
readerToGloopObject(Reader jsonReader)
Unmarshal a reader containing JSON data to a Gloop object.
|
static void |
writeJson(Writer writer,
GloopObject gloopObject,
boolean includeNulls,
boolean includeRoot,
boolean pretty)
Marshal a Gloop object to a writer.
|
@GloopParameter(name="gloopJson") public static String gloopObjectToJsonString(GloopObject gloopObject)
gloopObject
- the Gloop object to marshallpublic static String gloopObjectToJsonString(@GloopParameter(allowNull=false) GloopObject gloopObject, @GloopParameter(defaultValue="false") boolean includeRoot, @GloopParameter(defaultValue="false") boolean includeNulls)
gloopObject
- the Gloop object to marshallincludeRoot
- if gloopObject
is a model, this flag is used to determine whether or not
to include the name of the Gloop model in the root node of the JSON documentincludeNulls
- if true
, null
properties will be marshalledpublic static GloopObject jsonStringToGloopObject(String jsonString)
jsonString
- the JSON string to unmarshalpublic static GloopObject inputStreamToGloopObject(InputStream jsonInputStream)
jsonInputStream
- the stream containing the JSON string to unmarshalpublic static GloopObject readerToGloopObject(Reader jsonReader)
jsonReader
- the reader containing the JSON string to unmarshalpublic static void writeJson(@GloopParameter(allowNull=false) Writer writer, @GloopParameter(allowNull=false) GloopObject gloopObject, @GloopParameter(defaultValue="false") boolean includeNulls, @GloopParameter(defaultValue="false") boolean includeRoot, @GloopParameter(defaultValue="true") boolean pretty)
writer
- the writer where data will be written togloopObject
- the Gloop object to marshalincludeNulls
- if true
, null
properties will be marshalledincludeRoot
- if gloopObject
is a model, this flag is used to determine whether or not
to include the name of the Gloop model in the root node of the JSON documentpretty
- flag determining whether or not to write the JSON with indentation and new lines
to make it easier to readpublic static void printJson(@GloopParameter(allowNull=false) IndentPrinter printer, @GloopParameter(allowNull=false) GloopObject gloopObject, @GloopParameter(defaultValue="false") boolean includeNulls, @GloopParameter(defaultValue="false") boolean includeRoot, @GloopParameter(defaultValue="true") boolean pretty)
printer
- the printer where data will be written togloopObject
- the Gloop object to marshalincludeNulls
- if true
, null
properties will be marshalledincludeRoot
- if gloopObject
is a model, this flag is used to determine whether or not
to include the name of the Gloop model in the root node of the JSON documentpretty
- flag determining whether or not to write the JSON with indentation and new lines
to make it easier to read@GloopObjectParameter(value="gloopJsonCursor{\n gloopJsonCursor[]{\n nodeName\n cursorRecord:object\n }\n}") public static GloopCursor getInputCursorFromFile(String filename, @GloopParameter(defaultValue="UTF-8") String encoding, List<String> jsonNodeNames, GloopExecutionContext context) throws IOException
Parse a large JSON file.
Use the jsonNodeNames
argument to specify which nodes you want to extract from the JSON file.
Use $jsonRoot for root arrays.
This one-liner will return a Gloop cursor.
Every record in the cursor will point to a JSON object
that has the same name as any of the properties specified via jsonNodeNames
.
filename
- the name of the file containing the JSON dataencoding
- the encoding used by the JSON data; default value is UTF-8jsonNodeNames
- the names of the JSON objects to seek to whilst parsing the datacontext
- the Gloop execution context (automatically mapped by Gloop)jsonNodeNames
IOException
@GloopObjectParameter(value="gloopJsonCursor{\n gloopJsonCursor[]{\n nodeName\n cursorRecord:object\n }\n}") public static GloopCursor getInputCursorFromInputStream(InputStream inputStream, @GloopParameter(defaultValue="UTF-8") String encoding, List<String> jsonNodeNames, GloopExecutionContext context) throws IOException
Parse a large JSON stream.
Use the jsonNodeNames
argument to specify which nodes you want to extract from the JSON file.
Use $jsonRoot for root arrays.
This one-liner will return a Gloop cursor.
Every record in the cursor will point to a JSON object
that has the same name as any of the properties specified via jsonNodeNames
.
inputStream
- the stream containing the JSON dataencoding
- the encoding used by the JSON data; default value is UTF-8jsonNodeNames
- the names of the JSON objects to seek to whilst parsing the datacontext
- the Gloop execution context (automatically mapped by Gloop)jsonNodeNames
IOException
@GloopObjectParameter(value="output{\n jsonCursorOutput{\n indentPrinter:object:printer used to write the json out to::::groovy.util.IndentPrinter\n jsonOutputCursor[]*{\n }\n }\n}") public static GloopModel openJsonOutputCursor(@GloopParameter(defaultValue="true") boolean prettyPrint, @GloopParameter(defaultValue="true") boolean printStartDocumentBrace, @GloopParameter(defaultValue="true") boolean printCommaAtStart, @GloopParameter(defaultValue="true") boolean printStartArrayBracket, @GloopParameter(defaultValue="true") boolean printEndArrayBracket, @GloopParameter(defaultValue="true") boolean printEndDocumentBrace, String name, @GloopParameter(allowNull=false,defaultValue=" ") String indent, @GloopParameter(defaultValue="true") boolean closeDestination, Object destination, GloopExecutionContext context)
prettyPrint
- whether or not to write the JSON with indentation and new lines to make it easier to readprintStartDocumentBrace
- whether or not to print a start document character {
before outputting any cursor dataprintCommaAtStart
- whether or not to print comma before outputting any cursor dataprintStartArrayBracket
- whether or not to print an open array character [
before outputting any cursor dataprintEndArrayBracket
- whether or not to print an end array character ]
after outputting the cursor dataprintEndDocumentBrace
- whether or not to print an end document character }
after outputting the cursor dataname
- the name to print before declaring the array (null
if there is no name)indent
- the number of spaces used for indentation if prettyPrint
is true; the default is 4 spacescloseDestination
- set to true
if the cursor will close the underlying destination
after printing closing textdestination
- where to write the data to;
must be a StringBuffer
, Writer
, OutputStream
, Path
, or File
context
- the Gloop execution context (automatically mapped by Gloop)Copyright © 2023. All rights reserved.