Fixed #72
diff --git a/release-notes/VERSION b/release-notes/VERSION
index 391cc83..134f23e 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -3,6 +3,8 @@
Changes:
+#72: JsonFactory.copy() was not copying settings properly
+ (reported by Christian S (squiddle@github))
- Moved VERSION/LICENSE contained in jars under META-INF/, to resolve
Android packaging (APK) issues
diff --git a/src/main/java/com/fasterxml/jackson/core/JsonFactory.java b/src/main/java/com/fasterxml/jackson/core/JsonFactory.java
index 125de42..ccddb79 100644
--- a/src/main/java/com/fasterxml/jackson/core/JsonFactory.java
+++ b/src/main/java/com/fasterxml/jackson/core/JsonFactory.java
@@ -42,34 +42,15 @@
java.io.Serializable // since 2.1 (for Android, mostly)
{
/**
- * Computed for Jackson 2.1.0 release
+ * Computed for Jackson 2.2.0 release
*/
private static final long serialVersionUID = 8726401676402117450L;
- /**
- * Name used to identify JSON format
- * (and returned by {@link #getFormatName()}
+ /*
+ /**********************************************************
+ /* Helper types
+ /**********************************************************
*/
- public final static String FORMAT_NAME_JSON = "JSON";
-
- /**
- * Bitfield (set of flags) of all factory features that are enabled by default.
- */
- protected final static int DEFAULT_FACTORY_FEATURE_FLAGS = JsonFactory.Feature.collectDefaults();
-
- /**
- * Bitfield (set of flags) of all parser features that are enabled
- * by default.
- */
- protected final static int DEFAULT_PARSER_FEATURE_FLAGS = JsonParser.Feature.collectDefaults();
-
- /**
- * Bitfield (set of flags) of all generator features that are enabled
- * by default.
- */
- protected final static int DEFAULT_GENERATOR_FEATURE_FLAGS = JsonGenerator.Feature.collectDefaults();
-
- private final static SerializableString DEFAULT_ROOT_VALUE_SEPARATOR = DefaultPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR;
/**
* Enumeration that defines all on/off features that can only be
@@ -138,7 +119,39 @@
public boolean enabledIn(int flags) { return (flags & getMask()) != 0; }
public int getMask() { return (1 << ordinal()); }
- }
+ }
+
+ /*
+ /**********************************************************
+ /* Constants
+ /**********************************************************
+ */
+
+ /**
+ * Name used to identify JSON format
+ * (and returned by {@link #getFormatName()}
+ */
+ public final static String FORMAT_NAME_JSON = "JSON";
+
+ /**
+ * Bitfield (set of flags) of all factory features that are enabled by default.
+ */
+ protected final static int DEFAULT_FACTORY_FEATURE_FLAGS = JsonFactory.Feature.collectDefaults();
+
+ /**
+ * Bitfield (set of flags) of all parser features that are enabled
+ * by default.
+ */
+ protected final static int DEFAULT_PARSER_FEATURE_FLAGS = JsonParser.Feature.collectDefaults();
+
+ /**
+ * Bitfield (set of flags) of all generator features that are enabled
+ * by default.
+ */
+ protected final static int DEFAULT_GENERATOR_FEATURE_FLAGS = JsonGenerator.Feature.collectDefaults();
+
+ private final static SerializableString DEFAULT_ROOT_VALUE_SEPARATOR = DefaultPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR;
+
/*
/**********************************************************
/* Buffer, symbol table management
@@ -243,27 +256,53 @@
* and this reuse only works within context of a single
* factory instance.
*/
- public JsonFactory() { this(null); }
+ public JsonFactory() { this((ObjectCodec) null); }
public JsonFactory(ObjectCodec oc) { _objectCodec = oc; }
/**
+ * Constructor used when copy()ing a factory instance.
+ *
+ * @since 2.2.1
+ */
+ protected JsonFactory(JsonFactory src, ObjectCodec codec)
+ {
+ _objectCodec = null;
+ _factoryFeatures = src._factoryFeatures;
+ _parserFeatures = src._parserFeatures;
+ _generatorFeatures = src._generatorFeatures;
+ _characterEscapes = src._characterEscapes;
+ _inputDecorator = src._inputDecorator;
+ _outputDecorator = src._outputDecorator;
+ _rootValueSeparator = src._rootValueSeparator;
+
+ /* 27-Apr-2013, tatu: How about symbol table; should we try to
+ * reuse shared symbol tables? Could be more efficient that way;
+ * although can slightly add to concurrency overhead.
+ */
+ }
+
+ /**
* Method for constructing a new {@link JsonFactory} that has
* the same settings as this instance, but is otherwise
* independent (i.e. nothing is actually shared, symbol tables
* are separate).
* Note that {@link ObjectCodec} reference is not copied but is
* set to null; caller typically needs to set it after calling
- * this method.
+ * this method. Reason for this is that the codec is used for
+ * callbacks, and assumption is that there is strict 1-to-1
+ * mapping between codec, factory. Caller has to, then, explicitly
+ * set codec after making the copy.
*
* @since 2.1
*/
public JsonFactory copy()
{
_checkInvalidCopy(JsonFactory.class);
- return new JsonFactory(null);
+ // as per above, do clear ObjectCodec
+ return new JsonFactory(this, null);
}
-
+
/**
* @since 2.1
* @param exp
diff --git a/src/test/java/com/fasterxml/jackson/core/TestJsonFactory.java b/src/test/java/com/fasterxml/jackson/core/TestJsonFactory.java
new file mode 100644
index 0000000..9825685
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/core/TestJsonFactory.java
@@ -0,0 +1,28 @@
+package com.fasterxml.jackson.core;
+
+import com.fasterxml.jackson.test.BaseTest;
+
+public class TestJsonFactory extends BaseTest
+{
+ // #72
+ public void testCopy() throws Exception
+ {
+ JsonFactory jf = new JsonFactory();
+ // first, verify defaults
+ assertTrue(jf.isEnabled(JsonFactory.Feature.INTERN_FIELD_NAMES));
+ assertFalse(jf.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
+ assertFalse(jf.isEnabled(JsonGenerator.Feature.ESCAPE_NON_ASCII));
+ jf.disable(JsonFactory.Feature.INTERN_FIELD_NAMES);
+ jf.enable(JsonParser.Feature.ALLOW_COMMENTS);
+ jf.enable(JsonGenerator.Feature.ESCAPE_NON_ASCII);
+ // then change, verify that changes "stick"
+ assertFalse(jf.isEnabled(JsonFactory.Feature.INTERN_FIELD_NAMES));
+ assertTrue(jf.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
+ assertTrue(jf.isEnabled(JsonGenerator.Feature.ESCAPE_NON_ASCII));
+
+ JsonFactory jf2 = jf.copy();
+ assertFalse(jf2.isEnabled(JsonFactory.Feature.INTERN_FIELD_NAMES));
+ assertTrue(jf.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
+ assertTrue(jf.isEnabled(JsonGenerator.Feature.ESCAPE_NON_ASCII));
+ }
+}