[英]Can the Jackson parser be used to parse JSON5?
We'd like to parse JSON5 documents in the JVM, but the JSON5-specific libraries available on GitHub all appear to have very low support.我们想在 JVM 中解析JSON5文档,但GitHub 上可用的 JSON5 特定库似乎都支持非常低。 As parsers are often magnets for security vulnerabilities, we'd prefer not to use a parser that isn't already being widely used and scrutinised by the community.由于解析器通常是安全漏洞的磁铁,我们不希望使用尚未被社区广泛使用和审查的解析器。
This got us to wondering: Can the optional features of the Jackson JSON parser be used to parse JSON5?这让我们想知道:是否可以使用Jackson JSON 解析器的可选功能来解析 JSON5?
By enabling the following optional Jackson parser features:通过启用以下可选的 Jackson 解析器功能:
ALLOW_UNQUOTED_FIELD_NAMES
ALLOW_TRAILING_COMMA
ALLOW_SINGLE_QUOTES
ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER
ALLOW_NON_NUMERIC_NUMBERS
ALLOW_JAVA_COMMENTS
ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS
it seems possible to support all of JSON5's headline features except for:似乎可以支持所有 JSON5 的标题功能,除了:
Jackson hasa number of optional features which can be enabled on a parser to make it more lenient in the way it parses. Jackson 有许多可选功能,可以在解析器上启用这些功能,以使其解析方式更加宽松。
Comparing these parser options to the headline features of JSON5, we find that the following are supported:将这些解析器选项与 JSON5 的标题特性进行比较,我们发现支持以下内容:
Object keys may be an ECMAScript 5.1 IdentifierName.对象键可以是 ECMAScript 5.1 IdentifierName。
✅ Supported with the ALLOW_UNQUOTED_FIELD_NAMES
feature ✅ 支持ALLOW_UNQUOTED_FIELD_NAMES
功能
Objects may have a single trailing comma.对象可以有一个尾随逗号。
Arrays may have a single trailing comma.数组可以有一个尾随逗号。
✅ Both supported with the ALLOW_TRAILING_COMMA
feature ✅ 两者都支持ALLOW_TRAILING_COMMA
功能
Strings may be single quoted.字符串可以是单引号。
✅ Supported with the ALLOW_SINGLE_QUOTES
feature ✅ 支持ALLOW_SINGLE_QUOTES
功能
Strings may span multiple lines by escaping new line characters.通过转义换行符,字符串可以跨越多行。
Strings may include character escapes.字符串可能包括字符转义。
✅ Both of these appear to be supported by Jackson's ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER
feature, though the meaning or purpose of escaping here may differ subtly. ✅ 这两个似乎都得到Jackson 的ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER
特性的支持,尽管这里转义的含义或目的可能略有不同。 DYOR .迪奥。
Numbers may be IEEE 754 positive infinity, negative infinity, and NaN.数字可以是 IEEE 754 正无穷大、负无穷大和 NaN。
✅ Supported with the ALLOW_NON_NUMERIC_NUMBERS
feature ✅ 支持ALLOW_NON_NUMERIC_NUMBERS
功能
Single and multi-line comments are allowed.允许单行和多行注释。
✅ Supported with the ALLOW_JAVA_COMMENTS
feature. ✅ 支持ALLOW_JAVA_COMMENTS
功能。
The following JSON5 feature is partially supported by Jackson: Jackson部分支持以下 JSON5 功能:
Numbers may have a leading or trailing decimal point.数字可能有前导或尾随小数点。
✅ Leading decimal points are supported with the ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS
feature. ✅ ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS
功能支持前导小数点。
⛔️ Jackson doesn't appear to have support for trailing decimal points. ⛔️ Jackson 似乎不支持尾随小数点。
There doesn't currently (mid-2021) appear to be any way to configure Jackson to permit the following JSON5 features:目前(2021 年年中)似乎没有任何方法可以配置 Jackson 以允许以下 JSON5 功能:
Numbers may be hexadecimal.数字可以是十六进制。
Numbers may have a trailing decimal point.数字可能有一个尾随小数点。
Numbers may begin with an explicit plus sign.数字可能以明确的加号开头。
Additional white space characters are allowed.允许额外的空白字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.