From bc59123a543c1849553cc09b5c7ac7093804267a Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Wed, 28 Aug 2019 12:59:10 -0700 Subject: [PATCH] Ensure NullNode, MissingNode remain singleton --- .../fasterxml/jackson/databind/node/MissingNode.java | 10 +++++++++- .../com/fasterxml/jackson/databind/node/NullNode.java | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/node/MissingNode.java b/src/main/java/com/fasterxml/jackson/databind/node/MissingNode.java index acb6a916c0..69499c5e60 100644 --- a/src/main/java/com/fasterxml/jackson/databind/node/MissingNode.java +++ b/src/main/java/com/fasterxml/jackson/databind/node/MissingNode.java @@ -22,14 +22,22 @@ public final class MissingNode extends ValueNode { + private static final long serialVersionUID = 1L; + private final static MissingNode instance = new MissingNode(); /** *

- * NOTE: visibility raised to `protected` in 2.9.3 to allow custom subtypes. + * NOTE: visibility raised to `protected` in 2.9.3 to allow custom subtypes + * (which may not be greatest idea ever to have but was requested) */ protected MissingNode() { } + // To support JDK serialization, recovery of Singleton instance + protected Object readResolve() { + return instance; + } + @Override public boolean isMissingNode() { return true; diff --git a/src/main/java/com/fasterxml/jackson/databind/node/NullNode.java b/src/main/java/com/fasterxml/jackson/databind/node/NullNode.java index 1a222433bc..cb8f288659 100644 --- a/src/main/java/com/fasterxml/jackson/databind/node/NullNode.java +++ b/src/main/java/com/fasterxml/jackson/databind/node/NullNode.java @@ -15,6 +15,8 @@ public final class NullNode { // // Just need a fly-weight singleton + private static final long serialVersionUID = 1L; + public final static NullNode instance = new NullNode(); /** @@ -23,6 +25,11 @@ public final class NullNode */ protected NullNode() { } + // To support JDK serialization, recovery of Singleton instance + protected Object readResolve() { + return instance; + } + public static NullNode getInstance() { return instance; } @Override