Package groovy.json
Enum JsonParserType
- All Implemented Interfaces:
- Serializable,- Comparable<JsonParserType>,- java.lang.constant.Constable
Allows selection of parser type for new JsonSlurper.
 
 To enable the INDEX_OVERLAY parser do this:
 
             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.
- Since:
- 2.3.0
- 
Nested Class SummaryNested classes/interfaces inherited from class java.lang.EnumEnum.EnumDesc<E extends Enum<E>>
- 
Enum Constant SummaryEnum ConstantsEnum ConstantDescriptionThis 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.
- 
Method SummaryModifier and TypeMethodDescriptionstatic JsonParserTypeReturns the enum constant of this type with the specified name.static JsonParserType[]values()Returns an array containing the constants of this enum type, in the order they are declared.
- 
Enum Constant Details- 
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_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.
- 
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_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.
 
- 
- 
Method Details- 
valuesReturns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
 
- 
valueOfReturns 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.)- Parameters:
- name- the name of the enum constant to be returned.
- Returns:
- the enum constant with the specified name
- Throws:
- IllegalArgumentException- if this enum type has no constant with the specified name
- NullPointerException- if the argument is null
 
 
-