Implement [Issue#33]: make `JsonFactory` JDK Serializable
diff --git a/src/main/java/com/fasterxml/jackson/core/JsonFactory.java b/src/main/java/com/fasterxml/jackson/core/JsonFactory.java
index 3a76f35..d5805d4 100644
--- a/src/main/java/com/fasterxml/jackson/core/JsonFactory.java
+++ b/src/main/java/com/fasterxml/jackson/core/JsonFactory.java
@@ -47,9 +47,16 @@
*
* @author Tatu Saloranta
*/
-public class JsonFactory implements Versioned
+public class JsonFactory
+ implements Versioned,
+ java.io.Serializable // since 2.1 (for Android, mostly)
{
/**
+ * Computed for Jackson 2.1.0 release
+ */
+ private static final long serialVersionUID = -5207101305402257257L;
+
+ /**
* Name used to identify JSON format
* (and returned by {@link #getFormatName()}
*/
@@ -161,7 +168,7 @@
* It should not be linked back to the original blueprint, to
* avoid contents from leaking between factories.
*/
- protected CharsToNameCanonicalizer _rootCharSymbols = CharsToNameCanonicalizer.createRoot();
+ protected final transient CharsToNameCanonicalizer _rootCharSymbols = CharsToNameCanonicalizer.createRoot();
/**
* Alternative to the basic symbol table, some stream-based
@@ -170,7 +177,7 @@
* TODO: should clean up this; looks messy having 2 alternatives
* with not very clear differences.
*/
- protected BytesToNameCanonicalizer _rootByteSymbols = BytesToNameCanonicalizer.createRoot();
+ protected final transient BytesToNameCanonicalizer _rootByteSymbols = BytesToNameCanonicalizer.createRoot();
/*
/**********************************************************
@@ -278,6 +285,21 @@
+" (version: "+version()+") does not override copy(); it has to");
}
}
+
+ /*
+ /**********************************************************
+ /* Serializable overrides
+ /**********************************************************
+ */
+
+ /**
+ * Method that we need to override to actually make restoration go
+ * through constructors etc.
+ * Also: must be overridden by sub-classes as well.
+ */
+ protected Object readResolve() {
+ return new JsonFactory(_objectCodec);
+ }
/*
/**********************************************************