Skip to content

Commit 8a81e92

Browse files
committed
Adds SerializableJsonPointer as alternative to maintain usage of final
1 parent f53ef84 commit 8a81e92

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/main/java/com/fasterxml/jackson/core/JsonPointer.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.ObjectInput;
77
import java.io.ObjectOutput;
88
import java.io.ObjectStreamException;
9+
import java.io.Serializable;
910

1011
/**
1112
* Implementation of
@@ -22,7 +23,7 @@
2223
*
2324
* @since 2.3
2425
*/
25-
public class JsonPointer implements Externalizable
26+
public class JsonPointer implements Serializable
2627
{
2728
private static final long serialVersionUID = 1L;
2829
/**
@@ -65,10 +66,6 @@ public class JsonPointer implements Externalizable
6566
* so that {@link #toString} should be as efficient as possible.
6667
*/
6768
protected final String _asString;
68-
/**
69-
* Strictly used by serialization as an intermediate placeholder.
70-
*/
71-
private String _serialized;
7269

7370
protected final String _matchingPropertyName;
7471

@@ -655,16 +652,35 @@ private static void _appendEscape(StringBuilder sb, char c) {
655652
sb.append(c);
656653
}
657654

658-
@Override
659-
public void writeExternal(ObjectOutput out) throws IOException {
660-
out.writeUTF(_asString);
661-
}
662-
private Object readResolve() throws ObjectStreamException {
663-
return compile(_serialized);
655+
private Object writeReplace() {
656+
return new SerializableJsonPointer(_asString);
664657
}
665658

666-
@Override
667-
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
668-
_serialized = in.readUTF();
659+
/**
660+
* This must only exist to allow both final properties and implementation of
661+
* Externalizable/Serializable for JsonPointer
662+
*/
663+
private static class SerializableJsonPointer implements Externalizable {
664+
private String _asString;
665+
666+
public SerializableJsonPointer() {
667+
}
668+
669+
public SerializableJsonPointer(String asString) {
670+
_asString = asString;
671+
}
672+
673+
@Override
674+
public void writeExternal(ObjectOutput out) throws IOException {
675+
out.writeUTF(_asString);
676+
}
677+
678+
@Override
679+
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
680+
_asString = in.readUTF();
681+
}
682+
private Object readResolve() throws ObjectStreamException {
683+
return compile(_asString);
684+
}
669685
}
670686
}

0 commit comments

Comments
 (0)