Skip to content
Commits on Source (7)
language: java
# core streaming still builds on jdk6 and above:
# 05-Jan-2018, tatu: Not sure why, but travis build fails on jdk6 so leave it out
jdk:
- openjdk7
# 08-Dec-2018, tatu: While it should be possible to run core streaming on Java 6,
# build won't work with anything below Java 8 now
- openjdk8
- oraclejdk11
# Below this line is configuration for deploying to the Sonatype OSS repo
# http://blog.xeiam.com/2013/05/configure-travis-ci-to-deploy-snapshots.html
......@@ -14,7 +13,7 @@ after_success: "mvn deploy --settings target/travis/settings.xml"
branches:
only:
- master
- "2.9"
- "2.10"
# to make jdk6 work, as per: https://github.com/travis-ci/travis-ci/issues/8199
addons:
......
This copy of Jackson JSON processor annotations is licensed under the
Apache (Software) License, version 2.0 ("the License").
See the License for details about distribution rights, and the
specific rights regarding derivate works.
You may obtain a copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
......@@ -70,9 +70,6 @@ Alternatively, you have a `ObjectMapper` (from [Jackson Databind package](https:
JsonFactory factory = objectMapper.getFactory();
```
More information can be found from [Streaming API](http://wiki.fasterxml.com/JacksonStreamingApi
) at Jackson Wiki.
## Usage, simple reading
All reading is by using `JsonParser` (or its sub-classes, in case of data formats other than JSON),
......@@ -106,6 +103,4 @@ Note that the main differences compared to 1.0 core jar are:
* Project [Wiki](../../wiki) has JavaDocs and links to downloadable artifacts
* [Jackson Github Hub](https://github.com/FasterXML/jackson) has links to all official Jackson components
* [Jackson Github Doc](https://github.com/FasterXML/jackson-docs) is the hub for official Jackson documentation
* [FasterXML Jackson Project Wiki](http://wiki.fasterxml.com/JacksonHome) has additional documentation (especially for older Jackson versions)
* Commercial support (including alternative licensing arrangements) is available by [FasterXML.com](http://fasterxml.com)
jackson-core (2.10.0-1) unstable; urgency=medium
[ Mechtilde ]
* [a47457b] Corrected long line and typo in debian/changelog
* [a3fa1de] New upstream version 2.10.0
* [4ce8aee] adapt debian/patches/no-bundle.patch to new version
* [3640475] adapted debian/patches/series and added debian/patches/skip-jacoco.patch for the new version
* [ba009bd] changed debian/maven.properties to disable test, which need more dependencies
* [37c6c4e] added Rules-Requires-Root:no to debian/control
-- Mechtilde Stehmann <mechtilde@debian.org> Sat, 28 Sep 2019 17:36:22 +0200
jackson-core (2.9.9-1) unstable; urgency=medium
[ Mechtilde ]
......
......@@ -11,13 +11,14 @@ Build-Depends:
maven-debian-helper (>= 1.6.5),
xmlstarlet
Build-Depends-Indep:
default-jdk-doc,
junit4,
libmaven-bundle-plugin-java,
libmaven-enforcer-plugin-java,
libmaven-javadoc-plugin-java,
libreplacer-java
default-jdk-doc
, junit4
, libmaven-bundle-plugin-java
, libmaven-enforcer-plugin-java
, libmaven-javadoc-plugin-java
, libreplacer-java
Standards-Version: 4.4.0
Rules-Requires-Root: no
Vcs-Git: https://salsa.debian.org/java-team/jackson-core.git
Vcs-Browser: https://salsa.debian.org/java-team/jackson-core
Homepage: http://wiki.fasterxml.com/JacksonHome
......
# Include here properties to pass to Maven during the build.
# For example:
# maven.test.skip=true
maven.test.skip=true
maven.compiler.source=1.7
maven.compiler.target=1.7
project.build.sourceEncoding=UTF-8
From: Markus Koschany <apo@debian.org>
Date: Thu, 25 Jan 2018 18:34:20 +0100
Subject: junit
Fix a FTBFS because jackson-core ships jackson-base.pom. This is to avoid a
circular build-dependency. I am not sure if there is a better way (except
disabling the tests)
---
pom.xml | 8 ++++++++
1 file changed, 8 insertions(+)
--- a/pom.xml
+++ b/pom.xml
@@ -45,6 +45,15 @@
<jdk.module.name>com.fasterxml.jackson.core</jdk.module.name>
</properties>
+ <dependencies>
+ <dependency> <!-- all components use junit for testing -->
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.x</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
<!-- Alas, need to include snapshot reference since otherwise can not find
snapshot of parent... -->
<repositories>
From: Markus Koschany <apo@debian.org>
Date: Thu, 25 Jan 2018 22:36:30 +0100
Subject: maven enforcer
Maven Enforcer requires at least one valid rule. See also junit.patch.
---
pom.xml | 8 ++++++++
1 file changed, 8 insertions(+)
--- a/pom.xml
+++ b/pom.xml
@@ -67,6 +67,14 @@
<id>enforce-properties</id>
<phase>validate</phase>
<goals><goal>enforce</goal></goals>
+ <configuration>
+ <rules>
+ <requireMavenVersion>
+ <version>[3.0,)</version>
+ <message>[ERROR] The currently supported version of Maven is 3.0 or higher</message>
+ </requireMavenVersion>
+ </rules>
+ </configuration>
</execution>
</executions>
</plugin>
Description: no bundle
Description: packaging no bundle
Forwarded: No
Author: Mechtilde Stehmann <mechtilde@debian.org>
Last-Update: 2019-09-10
Last-Update: 2019-09-28
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
@@ -10,7 +10,7 @@
<artifactId>jackson-core</artifactId>
<name>Jackson-core</name>
<version>2.9.9</version>
<version>2.10.0</version>
- <packaging>bundle</packaging>
+ <packaging>jar</packaging>
<description>Core Jackson processing abstractions (aka Streaming API), implementation for JSON</description>
......
no-bundle.patch
junit.patch
maven-enforcer.patch
skip-jacoco.patch
Description: deactivate code coverage
Forwarded: No
Author: Mechtilde Stehmann <mechtilde@debian.org>
Last-Update: 2019-09-28
--- a/pom.xml
+++ b/pom.xml
@@ -57,7 +57,7 @@
<plugins>
<!-- 26-Aug-2019, tatu: JaCoCo for code coverage -->
- <plugin>
+ <!-- <plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
@@ -75,7 +75,7 @@
</goals>
</execution>
</executions>
- </plugin>
+ </plugin> -->
<!-- Important: enable enforcer plug-in: -->
<plugin>
......@@ -2,15 +2,14 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fasterxml.jackson</groupId>
<!-- For 2.9.2 and beyond, new parent pom; extends jackson-bom -->
<artifactId>jackson-base</artifactId>
<version>2.9.9</version>
<version>2.10.0</version>
</parent>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<name>Jackson-core</name>
<version>2.9.9</version>
<version>2.10.0</version>
<packaging>bundle</packaging>
<description>Core Jackson processing abstractions (aka Streaming API), implementation for JSON</description>
<inceptionYear>2008</inceptionYear>
......@@ -20,19 +19,18 @@
<connection>scm:git:git@github.com:FasterXML/jackson-core.git</connection>
<developerConnection>scm:git:git@github.com:FasterXML/jackson-core.git</developerConnection>
<url>http://github.com/FasterXML/jackson-core</url>
<tag>jackson-core-2.9.9</tag>
<tag>jackson-core-2.10.0</tag>
</scm>
<properties>
<!-- 16-Sep-2016, tatu: Retain Java6/JDK1.6 compatibility for streaming for Jackson 2.x -->
<!-- 04-Mar-2019, tatu: Retain Java6/JDK1.6 compatibility for annotations for Jackson 2.x,
but use Moditect to get JDK9+ module info support; need newer bundle plugin as well
-->
<javac.src.version>1.6</javac.src.version>
<javac.target.version>1.6</javac.target.version>
<!-- 04-May-2016, tatu: Bundle-plugin 3.x seems to require Java 7, so to
build for Java 6 need to downgrade here to last working 2.x version
(2.5.4 had some issues wrt shading)
-->
<version.plugin.bundle>2.5.3</version.plugin.bundle>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<osgi.export>com.fasterxml.jackson.core;version=${project.version},
com.fasterxml.jackson.core.*;version=${project.version}
......@@ -41,8 +39,6 @@ com.fasterxml.jackson.core.*;version=${project.version}
<!-- Generate PackageVersion.java into this directory. -->
<packageVersion.dir>com/fasterxml/jackson/core/json</packageVersion.dir>
<packageVersion.package>${project.groupId}.json</packageVersion.package>
<!-- usually above is fine for Automatic Module Name, but not here: -->
<jdk.module.name>com.fasterxml.jackson.core</jdk.module.name>
</properties>
<!-- Alas, need to include snapshot reference since otherwise can not find
......@@ -59,6 +55,28 @@ com.fasterxml.jackson.core.*;version=${project.version}
<build>
<plugins>
<!-- 26-Aug-2019, tatu: JaCoCo for code coverage -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Important: enable enforcer plug-in: -->
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
......@@ -96,6 +114,14 @@ com.fasterxml.jackson.core.*;version=${project.version}
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
</plugin>
<!-- 04-Mar-2019, tatu: Add rudimentary JDK9+ module info. To build with JDK 8
will have to use `moduleInfoFile` as anything else requires JDK 9+
-->
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
......
......@@ -155,6 +155,8 @@ Doug Roper (htmldoug@github)
* Suggested #463: Ensure that `skipChildren()` of non-blocking `JsonParser` will throw
exception if not enough input
(2.9.6)
* Reported, Contributed test for #563: Async parser does not keep track of Array context properly
(2.10.0)
Alexander Eyers-Taylor (aeyerstaylor@github)
* Reported #510: Fix ArrayIndexOutofBoundsException found by LGTM.com
......@@ -163,3 +165,31 @@ Alexander Eyers-Taylor (aeyerstaylor@github)
Henrik Gustafsson (gsson@github)
* Reported #516: _inputPtr off-by-one in UTF8StreamJsonParser._parseNumber2()
(2.9.9)
Alex Rebert (alpire@github)
* Reported #540, suggested fix: UTF8StreamJsonParser: fix byte to int conversion for
malformed escapes
(2.9.10)
* Reported #547: `CharsToNameCanonicalizer`: Internal error on `SymbolTable.rehash()` with high
number of hash collisions
(2.10.0)
* Reported #548: ByteQuadsCanonicalizer: ArrayIndexOutOfBoundsException in addName
(2.10.0)
Sam Smith (Oracle Security Researcher)
* Reported #540 (concurrently with Alex R, before fix was included)
(2.9.10)
Philippe Marschall (marschall@github)
* Requested #480: `SerializableString` value can not directly render to Writer
(2.10.0)
David Nault (dnault@github)
* Reported #531: Non-blocking parser reports incorrect locations when fed with
non-zero offset
(2.10.0)
Fabien Renaud (fabienrenaud@github)
* Reported, contributed fix fir #533: UTF-8 BOM not accounted for in
`JsonLocation.getByteOffset()`
(2.10.0)
......@@ -14,6 +14,49 @@ JSON library.
=== Releases ===
------------------------------------------------------------------------
2.10.0 (26-Sep-2019)
#433: Add Builder pattern for creating configured Stream factories
#464: Add "maximum unescaped char" configuration option for `JsonFactory` via builder
#467: Create `JsonReadFeature` to move JSON-specific `JsonParser.Feature`s to
#479: Improve thread-safety of buffer recycling
#480: `SerializableString` value can not directly render to Writer
(requested by Philippe M)
#481: Create `JsonWriteFeature` to move JSON-specific `JsonGenerator.Feature`s to
#484: Implement `UTF8JsonGenerator.writeRawValue(SerializableString)` (and
`writeRaw(..)`) more efficiently
#495: Create `StreamReadFeature` to move non-json specific `JsonParser.Feature`s to
#496: Create `StreamWriteFeature` to take over non-json-specific `JsonGenerator.Feature`s
#502: Make `DefaultPrettyPrinter.createInstance()` to fail for sub-classes
#506: Add missing type parameter for `TypeReference` in `ObjectCodec`
#508: Add new exception type `InputCoercionException` to be used for failed coercions
like overflow for `int`
#517: Add `JsonGenerator.writeStartObject(Object, int)` (needed by CBOR, maybe Avro)
#527: Add simple module-info for JDK9+, using Moditect
#533: UTF-8 BOM not accounted for in JsonLocation.getByteOffset()
(contributed by Fabien R)
#539: Reduce max size of recycled byte[]/char[] blocks by `TextBuffer`, `ByteArrayBuilder`
#547: `CharsToNameCanonicalizer`: Internal error on `SymbolTable.rehash()` with high
number of hash collisions
(reported by Alex R)
#548: ByteQuadsCanonicalizer: ArrayIndexOutOfBoundsException in addName
(reported by Alex R)
#549: Add configurability of "quote character" for JSON factory
#561: Misleading exception for unquoted String parsing
#563: Async parser does not keep track of Array context properly
(reported by Doug R)
- Rewrite `JsonGenerator.copyCurrentStructure()` to remove recursion)
- Add `missingNode()`, `nullNode()` in `TreeCodec`
- Add `JsonParserDelegate.delegate()` methods
2.9.10 (21-Sep-2019)
#540: UTF8StreamJsonParser: fix byte to int conversion for malformed escapes
(reported by Alex R and Sam S)
#556: 'IndexOutOfBoundsException' in UTF8JsonGenerator.writeString(Reader, len)
when using a negative length
(reported by jacob-alan-ward@github)
2.9.9 (16-May-2019)
#516: _inputPtr off-by-one in UTF8StreamJsonParser._parseNumber2()
......
......@@ -88,7 +88,7 @@ public final class Base64Variant
private final transient boolean _usesPadding;
/**
* Characted used for padding, if any ({@link #PADDING_CHAR_NONE} if not).
* Character used for padding, if any ({@link #PADDING_CHAR_NONE} if not).
*/
private final transient char _paddingChar;
......@@ -367,21 +367,17 @@ public final class Base64Variant
/**
* Convenience method for converting given byte array as base64 encoded String
* using this variant's settings,
* optionally enclosed in double-quotes.
* using this variant's settings, optionally enclosed in double-quotes.
* Linefeeds added, if needed, are expressed as 2-character JSON (and Java source)
* escape sequence of backslash + `n`.
*
* @param input Byte array to encode
* @param addQuotes Whether to surround resulting value in double quotes or not
*/
public String encode(byte[] input, boolean addQuotes)
{
int inputEnd = input.length;
StringBuilder sb;
{
// let's approximate... 33% overhead, ~= 3/8 (0.375)
int outputLen = inputEnd + (inputEnd >> 2) + (inputEnd >> 3);
sb = new StringBuilder(outputLen);
}
final int inputEnd = input.length;
final StringBuilder sb = new StringBuilder(inputEnd + (inputEnd >> 2) + (inputEnd >> 3));
if (addQuotes) {
sb.append('"');
}
......@@ -422,13 +418,61 @@ public final class Base64Variant
return sb.toString();
}
/**
* Convenience method for converting given byte array as base64 encoded String
* using this variant's settings, optionally enclosed in double-quotes.
* Linefeed character to use is passed explicitly.
*
* @param input Byte array to encode
* @param addQuotes Whether to surround resulting value in double quotes or not
*
* @since 2.10
*/
public String encode(byte[] input, boolean addQuotes, String linefeed)
{
final int inputEnd = input.length;
final StringBuilder sb = new StringBuilder(inputEnd + (inputEnd >> 2) + (inputEnd >> 3));
if (addQuotes) {
sb.append('"');
}
int chunksBeforeLF = getMaxLineLength() >> 2;
int inputPtr = 0;
int safeInputEnd = inputEnd-3;
while (inputPtr <= safeInputEnd) {
int b24 = ((int) input[inputPtr++]) << 8;
b24 |= ((int) input[inputPtr++]) & 0xFF;
b24 = (b24 << 8) | (((int) input[inputPtr++]) & 0xFF);
encodeBase64Chunk(sb, b24);
if (--chunksBeforeLF <= 0) {
sb.append(linefeed);
chunksBeforeLF = getMaxLineLength() >> 2;
}
}
int inputLeft = inputEnd - inputPtr;
if (inputLeft > 0) {
int b24 = ((int) input[inputPtr++]) << 16;
if (inputLeft == 2) {
b24 |= (((int) input[inputPtr++]) & 0xFF) << 8;
}
encodeBase64Partial(sb, b24, inputLeft);
}
if (addQuotes) {
sb.append('"');
}
return sb.toString();
}
/**
* Convenience method for decoding contents of a Base64-encoded String,
* using this variant's settings.
*
*
* @param input
*
* @since 2.2.3
*
* @since 2.3
*
* @throws IllegalArgumentException if input is not valid base64 encoded data
*/
......
package com.fasterxml.jackson.core;
import com.fasterxml.jackson.core.io.CharacterEscapes;
import com.fasterxml.jackson.core.io.SerializedString;
import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.core.json.JsonWriteFeature;
/**
* {@link com.fasterxml.jackson.core.TSFBuilder}
* implementation for constructing vanilla {@link JsonFactory}
* instances for reading/writing JSON encoded content.
*<p>
* NOTE: as of Jackson 2.x, use of JSON-specific builder is bit cumbersome
* since {@link JsonFactory} serves dual duty of base class AND actual
* implementation for JSON backend. This will be fixed in Jackson 3.0.
*
* @since 2.10
*/
public class JsonFactoryBuilder extends TSFBuilder<JsonFactory, JsonFactoryBuilder>
{
protected CharacterEscapes _characterEscapes;
protected SerializableString _rootValueSeparator;
protected int _maximumNonEscapedChar;
/**
* Character used for quoting field names (if field name quoting has not
* been disabled with {@link JsonWriteFeature#QUOTE_FIELD_NAMES})
* and JSON String values.
*/
protected char _quoteChar = JsonFactory.DEFAULT_QUOTE_CHAR;
public JsonFactoryBuilder() {
super();
_rootValueSeparator = JsonFactory.DEFAULT_ROOT_VALUE_SEPARATOR;
_maximumNonEscapedChar = 0;
}
public JsonFactoryBuilder(JsonFactory base) {
super(base);
_characterEscapes = base.getCharacterEscapes();
_rootValueSeparator = base._rootValueSeparator;
_maximumNonEscapedChar = base._maximumNonEscapedChar;
}
/*
/**********************************************************
/* Mutators
/**********************************************************
*/
// // // JSON-parsing features
@Override
public JsonFactoryBuilder enable(JsonReadFeature f) {
_legacyEnable(f.mappedFeature());
return this;
}
@Override
public JsonFactoryBuilder enable(JsonReadFeature first, JsonReadFeature... other) {
_legacyEnable(first.mappedFeature());
enable(first);
for (JsonReadFeature f : other) {
_legacyEnable(f.mappedFeature());
}
return this;
}
@Override
public JsonFactoryBuilder disable(JsonReadFeature f) {
_legacyDisable(f.mappedFeature());
return this;
}
@Override
public JsonFactoryBuilder disable(JsonReadFeature first, JsonReadFeature... other) {
_legacyDisable(first.mappedFeature());
for (JsonReadFeature f : other) {
_legacyEnable(f.mappedFeature());
}
return this;
}
@Override
public JsonFactoryBuilder configure(JsonReadFeature f, boolean state) {
return state ? enable(f) : disable(f);
}
// // // JSON-generating features
@Override
public JsonFactoryBuilder enable(JsonWriteFeature f) {
JsonGenerator.Feature old = f.mappedFeature();
if (old != null) {
_legacyEnable(old);
}
return this;
}
@Override
public JsonFactoryBuilder enable(JsonWriteFeature first, JsonWriteFeature... other) {
_legacyEnable(first.mappedFeature());
for (JsonWriteFeature f : other) {
_legacyEnable(f.mappedFeature());
}
return this;
}
@Override
public JsonFactoryBuilder disable(JsonWriteFeature f) {
_legacyDisable(f.mappedFeature());
return this;
}
@Override
public JsonFactoryBuilder disable(JsonWriteFeature first, JsonWriteFeature... other) {
_legacyDisable(first.mappedFeature());
for (JsonWriteFeature f : other) {
_legacyDisable(f.mappedFeature());
}
return this;
}
@Override
public JsonFactoryBuilder configure(JsonWriteFeature f, boolean state) {
return state ? enable(f) : disable(f);
}
// // // JSON-specific helper objects, settings
/**
* Method for defining custom escapes factory uses for {@link JsonGenerator}s
* it creates.
*/
public JsonFactoryBuilder characterEscapes(CharacterEscapes esc) {
_characterEscapes = esc;
return this;
}
/**
* Method that allows overriding String used for separating root-level
* JSON values (default is single space character)
*
* @param sep Separator to use, if any; null means that no separator is
* automatically added
*/
public JsonFactoryBuilder rootValueSeparator(String sep) {
_rootValueSeparator = (sep == null) ? null : new SerializedString(sep);
return this;
}
/**
* Method that allows overriding String used for separating root-level
* JSON values (default is single space character)
*
* @param sep Separator to use, if any; null means that no separator is
* automatically added
*/
public JsonFactoryBuilder rootValueSeparator(SerializableString sep) {
_rootValueSeparator = sep;
return this;
}
/**
* Method that allows specifying threshold beyond which all characters are
* automatically escaped (without checking possible custom escaping settings
* a la {@link #characterEscapes}: for example, to force escaping of all non-ASCII
* characters (set to 127), or all non-Latin-1 character (set to 255).
* Default setting is "disabled", specified by passing value of {@code 0} (or
* negative numbers).
*<p>
* NOTE! Lowest legal value (aside from marker 0) is 127: for ASCII range, other checks apply
* and this threshold is ignored. If value between [1, 126] is specified, 127 will be
* used instead.
*
* @param maxNonEscaped Highest character code that is NOT automatically escaped; if
* positive value above 0, or 0 to indicate that no automatic escaping is applied
* beside from what JSON specification requires (and possible custom escape settings).
* Values between 1 and 127 are all taken to behave as if 127 is specified: that is,
* no automatic escaping is applied in ASCII range.
*/
public JsonFactoryBuilder highestNonEscapedChar(int maxNonEscaped) {
_maximumNonEscapedChar = (maxNonEscaped <= 0) ? 0 : Math.max(127, maxNonEscaped);
return this;
}
/**
* Method that allows specifying an alternate
* character used for quoting field names (if field name quoting has not
* been disabled with {@link JsonWriteFeature#QUOTE_FIELD_NAMES})
* and JSON String values.
*<p>
* Default value is double-quote ({@code "}); typical alternative is
* single-quote/apostrophe ({@code '}).
*
* @param ch Character to use for quoting field names and JSON String values.
*/
public JsonFactoryBuilder quoteChar(char ch) {
// 12-Aug-2019, tatu: Due to implementation details, escaping characters beyond
// 7-bit ASCII set has deep overhead so let's limit set. If we absolutely
// must it is possible of course, but leads to problems combining with
// custom escaping aspects.
if (ch > 0x7F) {
throw new IllegalArgumentException("Can only use Unicode characters up to 0x7F as quote characters");
}
_quoteChar = ch;
return this;
}
// // // Accessors for JSON-specific settings
public CharacterEscapes characterEscapes() { return _characterEscapes; }
public SerializableString rootValueSeparator() { return _rootValueSeparator; }
public int highestNonEscapedChar() { return _maximumNonEscapedChar; }
public char quoteChar() { return _quoteChar; }
@Override
public JsonFactory build() {
// 28-Dec-2017, tatu: No special settings beyond base class ones, so:
return new JsonFactory(this);
}
}
......@@ -34,7 +34,7 @@ public abstract class JsonGenerator
*/
public enum Feature {
// // Low-level I/O / content features
/**
* Feature that determines whether generator will automatically
* close underlying output target that is NOT owned by the
......@@ -85,7 +85,10 @@ public abstract class JsonGenerator
* occurs when used straight from Javascript.
*<p>
* Feature is enabled by default (since it is required by JSON specification).
*
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonWriteFeature#QUOTE_FIELD_NAMES} instead
*/
@Deprecated
QUOTE_FIELD_NAMES(true),
/**
......@@ -99,15 +102,45 @@ public abstract class JsonGenerator
* output.
*<p>
* Feature is enabled by default.
*
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonWriteFeature#WRITE_NAN_AS_STRINGS} instead
*/
@Deprecated
QUOTE_NON_NUMERIC_NUMBERS(true),
// // Character escaping features
/**
* Feature that specifies that all characters beyond 7-bit ASCII
* range (i.e. code points of 128 and above) need to be output
* using format-specific escapes (for JSON, backslash escapes),
* if format uses escaping mechanisms (which is generally true
* for textual formats but not for binary formats).
*<p>
* Note that this setting may not necessarily make sense for all
* data formats (for example, binary formats typically do not use
* any escaping mechanisms; and some textual formats do not have
* general-purpose escaping); if so, settings is simply ignored.
* Put another way, effects of this feature are data-format specific.
*<p>
* Feature is disabled by default.
*
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonWriteFeature#ESCAPE_NON_ASCII} instead
*/
@Deprecated
ESCAPE_NON_ASCII(false),
// // Datatype coercion features
/**
* Feature that forces all Java numbers to be written as JSON strings.
* Feature that forces all Java numbers to be written as Strings,
* even if the underlying data format has non-textual representation
* (which is the case for JSON as well as all binary formats).
* Default state is 'false', meaning that Java numbers are to
* be serialized using basic numeric serialization (as JSON
* numbers, integral or floating point). If enabled, all such
* numeric values are instead written out as JSON Strings.
* numbers, integral or floating point, for example).
* If enabled, all such numeric values are instead written out as
* textual values (which for JSON means quoted in double-quotes).
*<p>
* One use case is to avoid problems with Javascript limitations:
* since Javascript standard specifies that all number handling
......@@ -116,7 +149,10 @@ public abstract class JsonGenerator
* accurately represent (as mantissa is only 51 bit wide).
*<p>
* Feature is disabled by default.
*
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonWriteFeature#WRITE_NUMBERS_AS_STRINGS} instead
*/
@Deprecated
WRITE_NUMBERS_AS_STRINGS(false),
/**
......@@ -124,54 +160,17 @@ public abstract class JsonGenerator
* serialized using {@link java.math.BigDecimal#toPlainString()} to prevent
* values to be written using scientific notation.
*<p>
* NOTE: only affects generators that serialize {@link java.math.BigDecimal}s
* using textual representation (textual formats but potentially some binary
* formats).
*<p>
* Feature is disabled by default, so default output mode is used; this generally
* depends on how {@link BigDecimal} has been created.
*
* @since 2.3
*/
WRITE_BIGDECIMAL_AS_PLAIN(false),
/**
* Feature that specifies that all characters beyond 7-bit ASCII
* range (i.e. code points of 128 and above) need to be output
* using format-specific escapes (for JSON, backslash escapes),
* if format uses escaping mechanisms (which is generally true
* for textual formats but not for binary formats).
*<p>
* Note that this setting may not necessarily make sense for all
* data formats (for example, binary formats typically do not use
* any escaping mechanisms; and some textual formats do not have
* general-purpose escaping); if so, settings is simply ignored.
* Put another way, effects of this feature are data-format specific.
*<p>
* Feature is disabled by default.
*/
ESCAPE_NON_ASCII(false),
// 23-Nov-2015, tatu: for [core#223], if and when it gets implemented
/**
* Feature that specifies handling of UTF-8 content that contains
* characters beyond BMP (Basic Multilingual Plane), which are
* represented in UCS-2 (Java internal character encoding) as two
* "surrogate" characters. If feature is enabled, these surrogate
* pairs are separately escaped using backslash escapes; if disabled,
* native output (4-byte UTF-8 sequence, or, with char-backed output
* targets, writing of surrogates as is which is typically converted
* by {@link java.io.Writer} into 4-byte UTF-8 sequence eventually)
* is used.
*<p>
* Note that the original JSON specification suggests use of escaping;
* but that this is not correct from standard UTF-8 handling perspective.
* Because of two competing goals, this feature was added to allow either
* behavior to be used, but defaulting to UTF-8 specification compliant
* mode.
*<p>
* Feature is disabled by default.
*
* @since Xxx
*/
// ESCAPE_UTF8_SURROGATES(false),
// // Schema/Validity support features
/**
......@@ -329,6 +328,13 @@ public abstract class JsonGenerator
*/
public abstract boolean isEnabled(Feature f);
/**
* @since 2.10
*/
public boolean isEnabled(StreamWriteFeature f) {
return isEnabled(f.mappedFeature());
}
/**
* Bulk access method for getting state of all standard (non-dataformat-specific)
* {@link JsonGenerator.Feature}s.
......@@ -401,12 +407,10 @@ public abstract class JsonGenerator
* @since 2.6
*/
public JsonGenerator overrideFormatFeatures(int values, int mask) {
throw new IllegalArgumentException("No FormatFeatures defined for generator of type "+getClass().getName());
/*
int oldState = getFeatureMask();
int newState = (oldState & ~mask) | (values & mask);
return setFeatureMask(newState);
*/
// 08-Oct-2018, tatu: For 2.10 we actually do get `JsonWriteFeature`s, although they
// are (for 2.x only, not for 3.x) mapper to legacy settings. So do not freak out:
// throw new IllegalArgumentException("No FormatFeatures defined for generator of type "+getClass().getName());
return this;
}
/*
......@@ -517,7 +521,7 @@ public abstract class JsonGenerator
* simply return 0.
*
* @return Currently active limitation for highest non-escaped character,
* if defined; or -1 to indicate no additional escaping is performed.
* if defined; or 0 to indicate no additional escaping is performed.
*/
public int getHighestEscapedChar() { return 0; }
......@@ -731,6 +735,7 @@ public abstract class JsonGenerator
*/
public abstract void writeStartArray() throws IOException;
// TODO: deprecate in 2.11 (remove from 3.0)
/**
* Method for writing start marker of an Array value, similar
* to {@link #writeStartArray()}, but also specifying how many
......@@ -749,7 +754,23 @@ public abstract class JsonGenerator
public void writeStartArray(int size) throws IOException {
writeStartArray();
}
/**
* @since 2.10
*/
public void writeStartArray(Object forValue) throws IOException {
writeStartArray();
setCurrentValue(forValue);
}
/**
* @since 2.10
*/
public void writeStartArray(Object forValue, int size) throws IOException {
writeStartArray(size);
setCurrentValue(forValue);
}
/**
* Method for writing closing marker of a JSON Array value
* (character ']'; plus possible white space decoration
......@@ -761,7 +782,7 @@ public abstract class JsonGenerator
public abstract void writeEndArray() throws IOException;
/**
* Method for writing starting marker of a JSON Object value
* Method for writing starting marker of an Object value
* (character '{'; plus possible white space decoration
* if pretty-printing is enabled).
*<p>
......@@ -772,10 +793,9 @@ public abstract class JsonGenerator
public abstract void writeStartObject() throws IOException;
/**
* Method for writing starting marker of a JSON Object value
* (character '{'; plus possible white space decoration
* if pretty-printing is enabled), to represent Java given
* as the argument. Argument is offered as metadata, but more
* Method for writing starting marker of an Object value
* to represent the given Java Object value.
* Argument is offered as metadata, but more
* importantly it should be assigned as the "current value"
* for the Object content that gets constructed and initialized.
*<p>
......@@ -783,7 +803,7 @@ public abstract class JsonGenerator
* are allowed: meaning everywhere except for when
* a field name is expected.
*
* @since 2.8.
* @since 2.8
*/
public void writeStartObject(Object forValue) throws IOException
{
......@@ -792,7 +812,29 @@ public abstract class JsonGenerator
}
/**
* Method for writing closing marker of a JSON Object value
* Method for writing starting marker of an Object value
* to represent the given Java Object value.
* Argument is offered as metadata, but more
* importantly it should be assigned as the "current value"
* for the Object content that gets constructed and initialized.
* In addition, caller knows number of key/value pairs ("properties")
* that will get written for the Object value: this is relevant for
* some format backends (but not, as an example, for JSON).
*<p>
* Object values can be written in any context where values
* are allowed: meaning everywhere except for when
* a field name is expected.
*
* @since 2.10
*/
public void writeStartObject(Object forValue, int size) throws IOException
{
writeStartObject();
setCurrentValue(forValue);
}
/**
* Method for writing closing marker of an Object value
* (character '}'; plus possible white space decoration
* if pretty-printing is enabled).
*<p>
......@@ -1091,6 +1133,7 @@ public abstract class JsonGenerator
*
* @since 2.1
*/
// public abstract void writeRaw(SerializableString raw) throws IOException;
public void writeRaw(SerializableString raw) throws IOException {
writeRaw(raw.getValue());
}
......@@ -1696,7 +1739,7 @@ public abstract class JsonGenerator
/**
* Convenience method for outputting a field entry ("member")
* (that will contain a JSON Object value), and the START_OBJECT marker.
* (that will contain an Object value), and the START_OBJECT marker.
* Equivalent to:
*<pre>
* writeFieldName(fieldName);
......@@ -1756,11 +1799,8 @@ public abstract class JsonGenerator
public void copyCurrentEvent(JsonParser p) throws IOException
{
JsonToken t = p.currentToken();
// sanity check; what to do?
if (t == null) {
_reportError("No current event to copy");
}
switch (t.id()) {
final int token = (t == null) ? ID_NOT_AVAILABLE : t.id();
switch (token) {
case ID_NOT_AVAILABLE:
_reportError("No current event to copy");
break; // never gets here
......@@ -1823,7 +1863,7 @@ public abstract class JsonGenerator
writeObject(p.getEmbeddedObject());
break;
default:
_throwInternal();
throw new IllegalStateException("Internal error: unknown current token, "+t);
}
}
......@@ -1860,37 +1900,116 @@ public abstract class JsonGenerator
public void copyCurrentStructure(JsonParser p) throws IOException
{
JsonToken t = p.currentToken();
if (t == null) {
_reportError("No current event to copy");
}
// Let's handle field-name separately first
int id = t.id();
int id = (t == null) ? ID_NOT_AVAILABLE : t.id();
if (id == ID_FIELD_NAME) {
writeFieldName(p.getCurrentName());
t = p.nextToken();
id = t.id();
id = (t == null) ? ID_NOT_AVAILABLE : t.id();
// fall-through to copy the associated value
}
switch (id) {
case ID_START_OBJECT:
writeStartObject();
while (p.nextToken() != JsonToken.END_OBJECT) {
copyCurrentStructure(p);
}
writeEndObject();
break;
_copyCurrentContents(p);
return;
case ID_START_ARRAY:
writeStartArray();
while (p.nextToken() != JsonToken.END_ARRAY) {
copyCurrentStructure(p);
}
writeEndArray();
break;
_copyCurrentContents(p);
return;
default:
copyCurrentEvent(p);
}
}
/**
* @since 2.10
*/
protected void _copyCurrentContents(JsonParser p) throws IOException
{
int depth = 1;
JsonToken t;
// Mostly copied from `copyCurrentEvent()`, but with added nesting counts
while ((t = p.nextToken()) != null) {
switch (t.id()) {
case ID_FIELD_NAME:
writeFieldName(p.getCurrentName());
break;
case ID_START_ARRAY:
writeStartArray();
++depth;
break;
case ID_START_OBJECT:
writeStartObject();
++depth;
break;
case ID_END_ARRAY:
writeEndArray();
if (--depth == 0) {
return;
}
break;
case ID_END_OBJECT:
writeEndObject();
if (--depth == 0) {
return;
}
break;
case ID_STRING:
if (p.hasTextCharacters()) {
writeString(p.getTextCharacters(), p.getTextOffset(), p.getTextLength());
} else {
writeString(p.getText());
}
break;
case ID_NUMBER_INT:
{
NumberType n = p.getNumberType();
if (n == NumberType.INT) {
writeNumber(p.getIntValue());
} else if (n == NumberType.BIG_INTEGER) {
writeNumber(p.getBigIntegerValue());
} else {
writeNumber(p.getLongValue());
}
break;
}
case ID_NUMBER_FLOAT:
{
NumberType n = p.getNumberType();
if (n == NumberType.BIG_DECIMAL) {
writeNumber(p.getDecimalValue());
} else if (n == NumberType.FLOAT) {
writeNumber(p.getFloatValue());
} else {
writeNumber(p.getDoubleValue());
}
break;
}
case ID_TRUE:
writeBoolean(true);
break;
case ID_FALSE:
writeBoolean(false);
break;
case ID_NULL:
writeNull();
break;
case ID_EMBEDDED_OBJECT:
writeObject(p.getEmbeddedObject());
break;
default:
throw new IllegalStateException("Internal error: unknown current token, "+t);
}
}
}
/*
/**********************************************************
/* Public API, context access
......
......@@ -5,6 +5,7 @@
package com.fasterxml.jackson.core;
import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.core.util.RequestPayload;
/**
......@@ -12,25 +13,13 @@ import com.fasterxml.jackson.core.util.RequestPayload;
* (content that does not conform to JSON syntax as per specification)
* is encountered.
*/
public class JsonParseException extends JsonProcessingException {
public class JsonParseException extends StreamReadException
{
private static final long serialVersionUID = 2L; // 2.7
// transient since 2.7.4
protected transient JsonParser _processor;
/**
* Optional payload that can be assigned to pass along for error reporting
* or handling purposes. Core streaming parser implementations DO NOT
* initialize this; it is up to using applications and frameworks to
* populate it.
*
* @since 2.8
*/
protected RequestPayload _requestPayload;
@Deprecated // since 2.7
public JsonParseException(String msg, JsonLocation loc) {
super(msg, loc);
super(msg, loc, null);
}
@Deprecated // since 2.7
......@@ -46,24 +35,21 @@ public class JsonParseException extends JsonProcessingException {
* @since 2.7
*/
public JsonParseException(JsonParser p, String msg) {
super(msg, (p == null) ? null : p.getCurrentLocation());
_processor = p;
super(p, msg);
}
/**
* @since 2.7
*/
public JsonParseException(JsonParser p, String msg, Throwable root) {
super(msg, (p == null) ? null : p.getCurrentLocation(), root);
_processor = p;
super(p, msg, root);
}
/**
* @since 2.7
*/
public JsonParseException(JsonParser p, String msg, JsonLocation loc) {
super(msg, loc);
_processor = p;
super(p, msg, loc);
}
/**
......@@ -71,7 +57,6 @@ public class JsonParseException extends JsonProcessingException {
*/
public JsonParseException(JsonParser p, String msg, JsonLocation loc, Throwable root) {
super(msg, loc, root);
_processor = p;
}
/**
......@@ -82,6 +67,7 @@ public class JsonParseException extends JsonProcessingException {
*
* @since 2.7
*/
@Override
public JsonParseException withParser(JsonParser p) {
_processor = p;
return this;
......@@ -95,49 +81,33 @@ public class JsonParseException extends JsonProcessingException {
*
* @since 2.8
*/
@Override
public JsonParseException withRequestPayload(RequestPayload p) {
_requestPayload = p;
return this;
}
// NOTE: overloaded in 2.10 just to retain binary compatibility with 2.9 (remove from 3.0)
@Override
public JsonParser getProcessor() {
return _processor;
return super.getProcessor();
}
/**
* Method that may be called to find payload that was being parsed, if
* one was specified for parser that threw this Exception.
*
* @return request body, if payload was specified; `null` otherwise
*
* @since 2.8
*/
// NOTE: overloaded in 2.10 just to retain binary compatibility with 2.9 (remove from 3.0)
@Override
public RequestPayload getRequestPayload() {
return _requestPayload;
return super.getRequestPayload();
}
/**
* The method returns the String representation of the request payload if
* one was specified for parser that threw this Exception.
*
* @return request body as String, if payload was specified; `null` otherwise
*
* @since 2.8
*/
// NOTE: overloaded in 2.10 just to retain binary compatibility with 2.9 (remove from 3.0)
@Override
public String getRequestPayloadAsString() {
return (_requestPayload != null) ? _requestPayload.toString() : null;
return super.getRequestPayloadAsString();
}
/**
* Overriding the getMessage() to include the request body
*/
// NOTE: overloaded in 2.10 just to retain binary compatibility with 2.9 (remove from 3.0)
@Override
public String getMessage() {
String msg = super.getMessage();
if (_requestPayload != null) {
msg += "\nRequest payload : " + _requestPayload.toString();
}
return msg;
return super.getMessage();
}
}
......@@ -43,9 +43,8 @@ public abstract class JsonParser
* Enumeration that defines all on/off features for parsers.
*/
public enum Feature {
// // // Low-level I/O handling features:
/**
* Feature that determines whether parser will automatically
* close underlying input source that is NOT owned by the
......@@ -73,6 +72,9 @@ public abstract class JsonParser
* this is extensively used. As such, feature is
* <b>disabled by default</b> for parsers and must be
* explicitly enabled.
*<p>
* NOTE: while not technically deprecated, since 2.10 recommended to use
* {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_JAVA_COMMENTS} instead.
*/
ALLOW_COMMENTS(false),
......@@ -87,9 +89,12 @@ public abstract class JsonParser
* this is a non-standard feature. As such, feature is
* <b>disabled by default</b> for parsers and must be
* explicitly enabled.
*<p>
* NOTE: while not technically deprecated, since 2.10 recommended to use
* {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_YAML_COMMENTS} instead.
*/
ALLOW_YAML_COMMENTS(false),
/**
* Feature that determines whether parser will allow use
* of unquoted field names (which is allowed by Javascript,
......@@ -98,6 +103,9 @@ public abstract class JsonParser
* Since JSON specification requires use of double quotes for
* field names,
* this is a non-standard feature, and as such disabled by default.
*<p>
* NOTE: while not technically deprecated, since 2.10 recommended to use
* {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_UNQUOTED_FIELD_NAMES} instead.
*/
ALLOW_UNQUOTED_FIELD_NAMES(false),
......@@ -111,6 +119,9 @@ public abstract class JsonParser
* Since JSON specification requires use of double quotes for
* field names,
* this is a non-standard feature, and as such disabled by default.
*<p>
* NOTE: while not technically deprecated, since 2.10 recommended to use
* {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_SINGLE_QUOTES} instead.
*/
ALLOW_SINGLE_QUOTES(false),
......@@ -124,7 +135,10 @@ public abstract class JsonParser
*<p>
* Since JSON specification requires quoting for all control characters,
* this is a non-standard feature, and as such disabled by default.
*
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_UNESCAPED_CONTROL_CHARS} instead
*/
@Deprecated
ALLOW_UNQUOTED_CONTROL_CHARS(false),
/**
......@@ -135,7 +149,10 @@ public abstract class JsonParser
*<p>
* Since JSON specification requires quoting for all control characters,
* this is a non-standard feature, and as such disabled by default.
*
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER} instead
*/
@Deprecated
ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER(false),
/**
......@@ -147,7 +164,10 @@ public abstract class JsonParser
*<p>
* Since JSON specification does not allow leading zeroes,
* this is a non-standard feature, and as such disabled by default.
*
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_LEADING_ZEROS_FOR_NUMBERS} instead
*/
@Deprecated
ALLOW_NUMERIC_LEADING_ZEROS(false),
/**
......@@ -167,7 +187,10 @@ public abstract class JsonParser
*<p>
* Since JSON specification does not allow use of such values,
* this is a non-standard feature, and as such disabled by default.
*/
*
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_NON_NUMERIC_NUMBERS} instead
*/
@Deprecated
ALLOW_NON_NUMERIC_NUMBERS(false),
/**
......@@ -185,7 +208,10 @@ public abstract class JsonParser
* feature and is disabled by default.
*
* @since 2.8
*
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_MISSING_VALUES} instead
*/
@Deprecated
ALLOW_MISSING_VALUES(false),
/**
......@@ -208,7 +234,10 @@ public abstract class JsonParser
* feature, and as such disabled by default.
*
* @since 2.9
*
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_TRAILING_COMMA} instead
*/
@Deprecated
ALLOW_TRAILING_COMMA(false),
// // // Validity checks
......@@ -277,7 +306,7 @@ public abstract class JsonParser
* @since 2.9
*/
INCLUDE_SOURCE_IN_LOCATION(true),
;
/**
......@@ -684,6 +713,13 @@ public abstract class JsonParser
*/
public boolean isEnabled(Feature f) { return f.enabledIn(_features); }
/**
* Method for checking whether specified {@link Feature} is enabled.
*
* @since 2.10
*/
public boolean isEnabled(StreamReadFeature f) { return f.mappedFeature().enabledIn(_features); }
/**
* Bulk access method for getting state of all standard {@link Feature}s.
*
......@@ -754,10 +790,10 @@ public abstract class JsonParser
* @since 2.6
*/
public JsonParser overrideFormatFeatures(int values, int mask) {
throw new IllegalArgumentException("No FormatFeatures defined for parser of type "+getClass().getName());
/*
_formatFeatures = (_formatFeatures & ~mask) | (values & mask);
*/
// 08-Oct-2018, tatu: For 2.10 we actually do get `JsonReadFeature`s, although they
// are (for 2.x only, not for 3.x) mapper to legacy settings. So do not freak out:
// throw new IllegalArgumentException("No FormatFeatures defined for parser of type "+getClass().getName());
return this;
}
/*
......@@ -1764,7 +1800,7 @@ public abstract class JsonParser
* Method for reading sequence of Objects from parser stream,
* all with same specified value type.
*/
public <T> Iterator<T> readValuesAs(TypeReference<?> valueTypeRef) throws IOException {
public <T> Iterator<T> readValuesAs(TypeReference<T> valueTypeRef) throws IOException {
return _codec().readValues(this, valueTypeRef);
}
......