public static final class JSONReader.Context
extends java.lang.Object
The Context class is responsible for:
Context instances can be created in several ways:
// Using default configuration
JSONReader.Context context = new JSONReader.Context();
// With specific features enabled
JSONReader.Context context = new JSONReader.Context(
JSONReader.Feature.FieldBased,
JSONReader.Feature.TrimString
);
// With custom date format
JSONReader.Context context = new JSONReader.Context("yyyy-MM-dd HH:mm:ss");
// With custom provider and features
ObjectReaderProvider provider = JSONFactory.getDefaultObjectReaderProvider();
JSONReader.Context context = new JSONReader.Context(provider,
JSONReader.Feature.FieldBased
);
Once created, a Context can be configured further:
context.setZoneId(ZoneId.of("UTC"));
context.setLocale(Locale.US);
context.setMaxLevel(1000);
context.setBufferSize(64 * 1024);
context.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
Context instances are typically used when creating JSONReader instances:
JSONReader.Context context = new JSONReader.Context();
context.config(JSONReader.Feature.FieldBased);
try (JSONReader reader = JSONReader.of(json, context)) {
MyObject obj = reader.read(MyObject.class);
}
Note that Context instances are not thread-safe and should not be shared between multiple concurrent reading operations. Each JSONReader should have its own Context instance or use the default context provided by factory methods.
JSONReader,
JSONReader.Feature,
ObjectReaderProvider| Modifier and Type | Field and Description |
|---|---|
(package private) java.util.function.Supplier<java.util.List> |
arraySupplier |
(package private) JSONReader.AutoTypeBeforeHandler |
autoTypeBeforeHandler |
(package private) int |
bufferSize |
(package private) java.lang.String |
dateFormat |
(package private) java.time.format.DateTimeFormatter |
dateFormatter |
(package private) ExtraProcessor |
extraProcessor |
(package private) long |
features |
(package private) boolean |
formatComplex |
(package private) boolean |
formatHasDay |
(package private) boolean |
formatHasHour |
(package private) boolean |
formatISO8601 |
(package private) boolean |
formatMillis |
(package private) boolean |
formatUnixTime |
(package private) boolean |
formatyyyyMMdd8 |
(package private) boolean |
formatyyyyMMddhhmmss19 |
(package private) boolean |
formatyyyyMMddhhmmssT19 |
(package private) java.util.Locale |
locale |
(package private) int |
maxLevel |
(package private) java.util.function.Supplier<java.util.Map> |
objectSupplier |
(package private) ObjectReaderProvider |
provider |
(package private) SymbolTable |
symbolTable |
(package private) java.util.TimeZone |
timeZone |
(package private) boolean |
useSimpleFormatter |
(package private) boolean |
yyyyMMddhhmm16 |
(package private) java.time.ZoneId |
zoneId |
| Constructor and Description |
|---|
Context(JSONReader.Feature... features)
Creates a new Context with the specified features.
|
Context(ObjectReaderProvider provider)
Creates a new Context with the specified object reader provider.
|
Context(ObjectReaderProvider provider,
Filter filter,
JSONReader.Feature... features)
Creates a new Context with the specified object reader provider, filter, and features.
|
Context(ObjectReaderProvider provider,
JSONReader.Feature... features)
Creates a new Context with the specified object reader provider and features.
|
Context(ObjectReaderProvider provider,
long features)
Creates a new Context with the specified object reader provider and features.
|
Context(ObjectReaderProvider provider,
SymbolTable symbolTable)
Creates a new Context with the specified object reader provider and symbol table.
|
Context(ObjectReaderProvider provider,
SymbolTable symbolTable,
Filter[] filters,
JSONReader.Feature... features)
Creates a new Context with the specified object reader provider, symbol table, filters, and features.
|
Context(ObjectReaderProvider provider,
SymbolTable symbolTable,
JSONReader.Feature... features)
Creates a new Context with the specified object reader provider, symbol table, and features.
|
Context(java.lang.String dateFormat,
JSONReader.Feature... features)
Creates a new Context with the specified date format and features.
|
| Modifier and Type | Method and Description |
|---|---|
void |
config(Filter filter)
Configures a filter for this context.
|
void |
config(Filter[] filters)
Configures filters for this context.
|
void |
config(Filter[] filters,
JSONReader.Feature... features)
Configures filters and features for this context.
|
void |
config(Filter filter,
JSONReader.Feature... features)
Configures a filter and features for this context.
|
void |
config(JSONReader.Feature... features)
Configures features for this context.
|
void |
config(JSONReader.Feature feature,
boolean state)
Configures a specific feature for this context.
|
java.util.function.Supplier<java.util.List> |
getArraySupplier()
Gets the array supplier configured for this context.
|
int |
getBufferSize()
Gets the buffer size configured for this context.
|
JSONReader.AutoTypeBeforeHandler |
getContextAutoTypeBeforeHandler()
Gets the AutoTypeBeforeHandler configured for this context.
|
java.lang.String |
getDateFormat()
Gets the date format pattern configured for this context.
|
java.time.format.DateTimeFormatter |
getDateFormatter()
Gets the date formatter configured for this context.
|
ExtraProcessor |
getExtraProcessor()
Gets the ExtraProcessor configured for this context.
|
long |
getFeatures()
Gets the features bitmask for this context.
|
java.util.Locale |
getLocale()
Gets the Locale configured for this context.
|
int |
getMaxLevel()
Gets the maximum nesting level allowed for this context.
|
ObjectReader |
getObjectReader(java.lang.reflect.Type type)
Gets an ObjectReader for the specified type.
|
ObjectReader |
getObjectReaderAutoType(long hashCode)
Gets an ObjectReader for the specified type hash code.
|
ObjectReader |
getObjectReaderAutoType(java.lang.String typeName,
java.lang.Class expectClass)
Gets an ObjectReader for the specified type name and expected class.
|
ObjectReader |
getObjectReaderAutoType(java.lang.String typeName,
java.lang.Class expectClass,
long features)
Gets an ObjectReader for the specified type name, expected class, and additional features.
|
java.util.function.Supplier<java.util.Map> |
getObjectSupplier()
Gets the object supplier configured for this context.
|
ObjectReaderProvider |
getProvider()
Gets the ObjectReaderProvider used by this context.
|
java.util.TimeZone |
getTimeZone()
Gets the TimeZone configured for this context.
|
java.time.ZoneId |
getZoneId()
Gets the ZoneId configured for this context.
|
boolean |
isEnabled(JSONReader.Feature feature)
Checks if the specified feature is enabled in this context.
|
boolean |
isFormatHasHour()
Checks if the context is configured to format dates with hour information.
|
boolean |
isFormatISO8601()
Checks if the context is configured to format dates in ISO8601 format.
|
boolean |
isFormatMillis()
Checks if the context is configured to format milliseconds.
|
boolean |
isFormatUnixTime()
Checks if the context is configured to format Unix time.
|
boolean |
isFormatyyyyMMdd8()
Checks if the context is configured to format dates in yyyyMMdd format (8 characters).
|
boolean |
isFormatyyyyMMddhhmmss19()
Checks if the context is configured to format dates in yyyyMMddHHmmss format (19 characters).
|
boolean |
isFormatyyyyMMddhhmmssT19()
Checks if the context is configured to format dates in yyyy-MM-dd'T'HH:mm:ss format (19 characters).
|
void |
setArraySupplier(java.util.function.Supplier<java.util.List> arraySupplier)
Sets the array supplier for this context.
|
JSONReader.Context |
setBufferSize(int bufferSize)
Sets the buffer size for this context.
|
void |
setDateFormat(java.lang.String format)
Sets the date format pattern for this context.
|
void |
setDateFormatter(java.time.format.DateTimeFormatter dateFormatter)
Sets the date formatter for this context.
|
void |
setExtraProcessor(ExtraProcessor extraProcessor)
Sets the ExtraProcessor for this context.
|
void |
setFeatures(long features)
Sets the features bitmask for this context.
|
void |
setLocale(java.util.Locale locale)
Sets the Locale for this context.
|
void |
setMaxLevel(int maxLevel)
Sets the maximum nesting level allowed for this context.
|
void |
setObjectSupplier(java.util.function.Supplier<java.util.Map> objectSupplier)
Sets the object supplier for this context.
|
void |
setTimeZone(java.util.TimeZone timeZone)
Sets the TimeZone for this context.
|
void |
setZoneId(java.time.ZoneId zoneId)
Sets the ZoneId for this context.
|
java.lang.String dateFormat
boolean formatComplex
boolean formatyyyyMMddhhmmss19
boolean formatyyyyMMddhhmmssT19
boolean yyyyMMddhhmm16
boolean formatyyyyMMdd8
boolean formatMillis
boolean formatUnixTime
boolean formatISO8601
boolean formatHasDay
boolean formatHasHour
boolean useSimpleFormatter
int maxLevel
int bufferSize
java.time.format.DateTimeFormatter dateFormatter
java.time.ZoneId zoneId
long features
java.util.Locale locale
java.util.TimeZone timeZone
java.util.function.Supplier<java.util.Map> objectSupplier
java.util.function.Supplier<java.util.List> arraySupplier
JSONReader.AutoTypeBeforeHandler autoTypeBeforeHandler
ExtraProcessor extraProcessor
final ObjectReaderProvider provider
final SymbolTable symbolTable
public Context(ObjectReaderProvider provider)
provider - the object reader provider to usepublic Context(ObjectReaderProvider provider, long features)
provider - the object reader provider to usefeatures - the initial features bitmaskpublic Context(JSONReader.Feature... features)
features - the features to enablepublic Context(java.lang.String dateFormat,
JSONReader.Feature... features)
dateFormat - the date format pattern to usefeatures - the features to enablepublic Context(ObjectReaderProvider provider, JSONReader.Feature... features)
provider - the object reader provider to usefeatures - the features to enablepublic Context(ObjectReaderProvider provider, Filter filter, JSONReader.Feature... features)
provider - the object reader provider to usefilter - the filter to configurefeatures - the features to enablepublic Context(ObjectReaderProvider provider, SymbolTable symbolTable)
provider - the object reader provider to usesymbolTable - the symbol table to usepublic Context(ObjectReaderProvider provider, SymbolTable symbolTable, JSONReader.Feature... features)
provider - the object reader provider to usesymbolTable - the symbol table to usefeatures - the features to enablepublic Context(ObjectReaderProvider provider, SymbolTable symbolTable, Filter[] filters, JSONReader.Feature... features)
provider - the object reader provider to usesymbolTable - the symbol table to usefilters - the filters to configurefeatures - the features to enablepublic boolean isFormatUnixTime()
public boolean isFormatyyyyMMddhhmmss19()
public boolean isFormatyyyyMMddhhmmssT19()
public boolean isFormatyyyyMMdd8()
public boolean isFormatMillis()
public boolean isFormatISO8601()
public boolean isFormatHasHour()
public ObjectReader getObjectReader(java.lang.reflect.Type type)
type - The type for which to get an ObjectReaderpublic ObjectReaderProvider getProvider()
public ObjectReader getObjectReaderAutoType(long hashCode)
hashCode - The hash code of the typepublic ObjectReader getObjectReaderAutoType(java.lang.String typeName, java.lang.Class expectClass)
typeName - The type nameexpectClass - The expected classpublic JSONReader.AutoTypeBeforeHandler getContextAutoTypeBeforeHandler()
public ObjectReader getObjectReaderAutoType(java.lang.String typeName, java.lang.Class expectClass, long features)
typeName - The type nameexpectClass - The expected classfeatures - Additional features to considerpublic ExtraProcessor getExtraProcessor()
public void setExtraProcessor(ExtraProcessor extraProcessor)
extraProcessor - The ExtraProcessor to setpublic java.util.function.Supplier<java.util.Map> getObjectSupplier()
public void setObjectSupplier(java.util.function.Supplier<java.util.Map> objectSupplier)
objectSupplier - The object supplier to setpublic java.util.function.Supplier<java.util.List> getArraySupplier()
public void setArraySupplier(java.util.function.Supplier<java.util.List> arraySupplier)
arraySupplier - The array supplier to setpublic java.time.format.DateTimeFormatter getDateFormatter()
public void setDateFormatter(java.time.format.DateTimeFormatter dateFormatter)
dateFormatter - The DateTimeFormatter to setpublic java.lang.String getDateFormat()
public void setDateFormat(java.lang.String format)
format - The date format pattern to setpublic java.time.ZoneId getZoneId()
public long getFeatures()
public void setFeatures(long features)
features - The features bitmask to setpublic void setZoneId(java.time.ZoneId zoneId)
zoneId - The ZoneId to setpublic int getMaxLevel()
public void setMaxLevel(int maxLevel)
maxLevel - The maximum nesting level to setpublic int getBufferSize()
public JSONReader.Context setBufferSize(int bufferSize)
bufferSize - The buffer size to set in bytesjava.lang.IllegalArgumentException - if bufferSize is negativepublic java.util.Locale getLocale()
public void setLocale(java.util.Locale locale)
locale - The Locale to setpublic java.util.TimeZone getTimeZone()
public void setTimeZone(java.util.TimeZone timeZone)
timeZone - The TimeZone to setpublic void config(JSONReader.Feature... features)
features - The features to enablepublic void config(Filter filter, JSONReader.Feature... features)
filter - The filter to configurefeatures - The features to enablepublic void config(Filter filter)
filter - The filter to configurepublic void config(Filter[] filters, JSONReader.Feature... features)
filters - The filters to configurefeatures - The features to enablepublic void config(Filter[] filters)
filters - The filters to configurepublic boolean isEnabled(JSONReader.Feature feature)
feature - The feature to checkpublic void config(JSONReader.Feature feature, boolean state)
feature - The feature to configurestate - true to enable the feature, false to disable it