- All Implemented Interfaces:
public enum JsonParserType extends java.lang.Enum<JsonParserType>
INDEX_OVERLAY should be your parser of choice. CHAR_BUFFER is the parser of choice due to element of least surprise and need to mimic existing Slurper behavior as much as possible. Use CHARACTER_SOURCE for large file parsing. Use LAX if you want to enable relaxed JSON parsing, i.e., allow comments, no quote strings, etc. Use CHAR_BUFFER for a non-fancy but super fast parser.parser = new JsonSlurper().setType(JsonParserType.INDEX_OVERLAY);
Parser speed in order: INDEX_OVERLAY, LAX, CHAR_BUFFER, CHARACTER_SOURCE.Use Cases:
Use LAX for config files as it allows comments. Use INDEX_OVERLAY for REST calls, WebSocket messages, AJAX, inter process communication, etc. Use CHAR_BUFFER if eager parsing of ints, dates, longs, are appealing. Use CHARACTER_SOURCE if you are dealing with large JSON files over 2MB. INDEX_OVERLAY is highly tuned for object deserialization from JSON.
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
java.lang.Enum.EnumDesc<E extends java.lang.Enum<E>>
Enum Constant Summary
Enum Constants Enum Constant DescriptionThis is a basic parser with no index overlay.Parser uses an abstraction that allows it to handle any size file by using a char  windowing, built on top or Reader.Fastest parser, but has pointers (indexes really) to original char buffer.LAX mode allows keys with no quotes, keys with single quotes, strings elements in JSON with no quotes or single quotes.
Methods inherited from class java.lang.Enum
clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
Enum Constant Details
INDEX_OVERLAYpublic static final JsonParserType INDEX_OVERLAYFastest parser, but has pointers (indexes really) to original char buffer. Care must be used if putting parse maps into a long term cache as members of map maybe index overlay objects pointing to original buffer. You can mitigate these risks by using chop and lazy chop. Chop eagerly dices up the buffer so each Value element points to a small copy of the original buffer. Lazy Chop dices up the buffer when a list get or map get is called so if an GPath expression or such is applied. You do not need chop or lazy chop if you are not putting the map into a long term cache. You do not need chop or lazy chop if you are doing object de-serialization. Recommendation is to use this for JSON buffers under 2MB.
CHARACTER_SOURCEpublic static final JsonParserType CHARACTER_SOURCEParser uses an abstraction that allows it to handle any size file by using a char  windowing, built on top or Reader. This parser is slower than INDEX_OVERLAY and CHAR_BUFFER, but can handle really large files without OOM exceptions. Although slower than other groovy parsers it is as fast as many common JSON parsers. Recommendation is to use this for JSON buffers over 2MB.
LAXpublic static final JsonParserType LAXLAX mode allows keys with no quotes, keys with single quotes, strings elements in JSON with no quotes or single quotes. It also allows comments //, # and even multi-line /* comments. LAX is an INDEX_OVERLAY parser. Its speed is comparable to INDEX_OVERLAY. It is slightly slower than INDEX_OVERLAY, but faster than the other options.
CHAR_BUFFERpublic static final JsonParserType CHAR_BUFFERThis is a basic parser with no index overlay. It is wicked fast, but not as fast at the INDEX_OVERLAY. It should be on average the fastest known JSON parser on the JVM circa Jan 2014. But not as fast as INDEX_OVERLAY.
valuespublic static JsonParserType values()Returns an array containing the constants of this enum type, in the order they are declared.
- an array containing the constants of this enum type, in the order they are declared
valueOfpublic static JsonParserType valueOf(java.lang.String name)Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
name- the name of the enum constant to be returned.
- the enum constant with the specified name
java.lang.IllegalArgumentException- if this enum type has no constant with the specified name
java.lang.NullPointerException- if the argument is null