java.lang.Object
io.jstach.ezkv.json5.JSON5KeyValuesMedia
- All Implemented Interfaces:
- KeyValuesMedia,- KeyValuesServiceProvider,- KeyValuesServiceProvider.KeyValuesMediaFinder
Parses JSON5 to KeyValues. The 
 Here is the corresponding key values (notice duplicates):
 
 
 We will get flattened key values that look like:
 
 Because both formats may not be what you want you might want to use a
 filter  to clean up the results.
 
parser() can
 also be used for strict JSON as JSON5 is a true superset.
 
 The constants in this class are important and describe parameters that can be set on the
 KeyValuesResource.
 
JSON is not flat and is more of a tree where as EZKV KeyValues are and only support string values. Thus the parser flattens the JSON based on some heuristics. JSON objects are easy to flatten but JSON arrays need special handling.
Here is an example of the default flattening:	{
		"a": {
			"b": [1, 2.0, {"c": 3}],
			"d": "value"
		}
	}
a.b=1
a.b=2.0
a.b.c=3
a.d=value
Because EZKV supports duplicates and order matters the data is not lost but this might be confusing. Another option is to generate array indices in the keys.
Assume we load a resource with the previous JSON like:
_load_a=classpath:/a.json5?_param_json5_arraykey=array
a.b[0]=1
a.b[1]=2.0
a.b[2].c=3
a.d=value
 This module does have a service loader registration. If you do not wish to use the
 Service Loader you can add an instance of this class to
 KeyValuesSystem.Builder.
 
- See Also:
- API Note
- This is not included with the core ezkv module because JSON5 is still evolving and likely to keep changing.
- 
Nested Class SummaryNested classes/interfaces inherited from interface io.jstach.ezkv.kvs.KeyValuesMediaKeyValuesMedia.Formatter, KeyValuesMedia.ParserNested classes/interfaces inherited from interface io.jstach.ezkv.kvs.KeyValuesServiceProviderKeyValuesServiceProvider.KeyValuesFilter, KeyValuesServiceProvider.KeyValuesLoaderFinder, KeyValuesServiceProvider.KeyValuesMediaFinder, KeyValuesServiceProvider.KeyValuesProvider
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringWill output array keys using array notation likea[0]instead of the default which is duplicating the keys.static final StringWill duplicate keys for array entries.static final StringThis parameter controls the array key naming scheme and is set withKeyValuesResource.parameters().static final StringThe default JSON path separator.static final StringThe file ext is "json5" and notjsonhowever this media will work forjsonextension.static final StringThe media type is "application/json5" and notapplication/jsonhowever this media will work for normal json.static final StringConfigures whether or not to use the raw JSON5 number found instead of the Java converted number inKeyValuesResource.parameters()with the key "json5_number_raw" and is by defaultfalse.static final StringConfigures the separator byKeyValuesResource.parameters()with the key "json5_separator" and is by default ".".Fields inherited from interface io.jstach.ezkv.kvs.KeyValuesMediaFILE_EXT_PROPERTIES, MEDIA_TYPE_PROPERTIES, MEDIA_TYPE_URLENCODEDFields inherited from interface io.jstach.ezkv.kvs.KeyValuesServiceProviderBUILTIN_ORDER_START
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionfindByMediaType(String mediaType) Finds aKeyValuesMediabased on a media type string.Returns aKeyValuesMedia.Formatterfor formatting key-value pairs to an appendable target.@Nullable StringReturns the file extension associated with the media type, if any.Returns the media type as a string and should ideally be in rfc6838 format, is required and should be unique from otherKeyValuesMediaunlikeKeyValuesMedia.getFileExt().booleanhasFileExt(String filename) Checks if a given filename has the file extension associated with this media type.parser()Returns aKeyValuesMedia.Parserfor parsing key-value pairs from an input stream.Returns a parser that maybe customized by parameters.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.jstach.ezkv.kvs.KeyValuesMediafindByExt, findByUri, hasFileExtMethods inherited from interface io.jstach.ezkv.kvs.KeyValuesServiceProviderorderMethods inherited from interface io.jstach.ezkv.kvs.KeyValuesServiceProvider.KeyValuesMediaFinderfindByResource
- 
Field Details- 
MEDIA_TYPEThe media type is "application/json5" and notapplication/jsonhowever this media will work for normal json.- See Also:
 
- 
FILE_EXTThe file ext is "json5" and notjsonhowever this media will work forjsonextension.- See Also:
 
- 
ARRAY_KEY_PARAMThis parameter controls the array key naming scheme and is set withKeyValuesResource.parameters(). The two values are "duplicate" (default) and "array". An example is:_load_a=classpath:/a.json5?_param_json5_arraykey=array- See Also:
 
- 
ARRAY_KEY_ARRAY_VALUEWill output array keys using array notation likea[0]instead of the default which is duplicating the keys.- See Also:
 
- 
ARRAY_KEY_DUPLICATE_VALUEWill duplicate keys for array entries. For example{ "a" : [ 1, 2 ] }will bea=1 a=2- See Also:
 
- 
SEPARATOR_PARAMConfigures the separator byKeyValuesResource.parameters()with the key "json5_separator" and is by default ".".- See Also:
 
- 
DEFAULT_SEPARATORThe default JSON path separator.- See Also:
 
- 
NUMBER_RAW_PARAMConfigures whether or not to use the raw JSON5 number found instead of the Java converted number inKeyValuesResource.parameters()with the key "json5_number_raw" and is by defaultfalse. An example is if one used hexadecimal-0xC0FFEEit normally would be converted to an integer.Will yield key values:{ "number" : -0xC0FFEE}Note that exponents in JSON5 work different than in Java so downstream configuration parsing will have to deal with this if this is turned on but otherwise most of JSON5 number format is a compatible subset of Java.# Normally the below would happen # number=-12648430 # But will now be number=-0xC0FFEE- See Also:
 
 
- 
- 
Constructor Details- 
JSON5KeyValuesMediapublic JSON5KeyValuesMedia()For service loader.
 
- 
- 
Method Details- 
getMediaTypeDescription copied from interface:KeyValuesMediaReturns the media type as a string and should ideally be in rfc6838 format, is required and should be unique from otherKeyValuesMediaunlikeKeyValuesMedia.getFileExt(). For implementers if there is not a registered media type a recommendation is to useapplication/x-extwhere "ext" would be replaced with the file extension or some name.- Specified by:
- getMediaTypein interface- KeyValuesMedia
- Returns:
- the media type
 
- 
getFileExtDescription copied from interface:KeyValuesMediaReturns the file extension associated with the media type, if any. The first period "." should not be included. For example.tar.gzshould betar.gz.- Specified by:
- getFileExtin interface- KeyValuesMedia
- Returns:
- the file extension or nullif not applicable
 
- 
parserDescription copied from interface:KeyValuesMediaReturns aKeyValuesMedia.Parserfor parsing key-value pairs from an input stream.- Specified by:
- parserin interface- KeyValuesMedia
- Returns:
- the parser
 
- 
parserDescription copied from interface:KeyValuesMediaReturns a parser that maybe customized by parameters. By defaultKeyValuesMedia.parser()is called.- Specified by:
- parserin interface- KeyValuesMedia
- Parameters:
- parameters- parameters that can come from- KeyValuesResource.parameters().
- Returns:
- parser
 
- 
formatterDescription copied from interface:KeyValuesMediaReturns aKeyValuesMedia.Formatterfor formatting key-value pairs to an appendable target. By default, this method throwsUnsupportedOperationExceptionif formatting is not supported.- Specified by:
- formatterin interface- KeyValuesMedia
- Returns:
- the formatter
 
- 
findByMediaTypeDescription copied from interface:KeyValuesServiceProvider.KeyValuesMediaFinderFinds aKeyValuesMediabased on a media type string.- Specified by:
- findByMediaTypein interface- KeyValuesMedia
- Specified by:
- findByMediaTypein interface- KeyValuesServiceProvider.KeyValuesMediaFinder
- Parameters:
- mediaType- the media type (e.g., "application/json")
- Returns:
- an Optionalcontaining the media if found, or empty if not
 
- 
hasFileExtDescription copied from interface:KeyValuesMediaChecks if a given filename has the file extension associated with this media type.- Specified by:
- hasFileExtin interface- KeyValuesMedia
- Parameters:
- filename- the filename to check
- Returns:
- trueif the filename ends with the media type's file extension, otherwise- false
 
 
-