|
6 | 6 | import java.io.ObjectInput;
|
7 | 7 | import java.io.ObjectOutput;
|
8 | 8 | import java.io.ObjectStreamException;
|
| 9 | +import java.io.Serializable; |
9 | 10 |
|
10 | 11 | /**
|
11 | 12 | * Implementation of
|
|
22 | 23 | *
|
23 | 24 | * @since 2.3
|
24 | 25 | */
|
25 |
| -public class JsonPointer implements Externalizable |
| 26 | +public class JsonPointer implements Serializable |
26 | 27 | {
|
27 | 28 | private static final long serialVersionUID = 1L;
|
28 | 29 | /**
|
@@ -65,10 +66,6 @@ public class JsonPointer implements Externalizable
|
65 | 66 | * so that {@link #toString} should be as efficient as possible.
|
66 | 67 | */
|
67 | 68 | protected final String _asString;
|
68 |
| - /** |
69 |
| - * Strictly used by serialization as an intermediate placeholder. |
70 |
| - */ |
71 |
| - private String _serialized; |
72 | 69 |
|
73 | 70 | protected final String _matchingPropertyName;
|
74 | 71 |
|
@@ -655,16 +652,35 @@ private static void _appendEscape(StringBuilder sb, char c) {
|
655 | 652 | sb.append(c);
|
656 | 653 | }
|
657 | 654 |
|
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); |
664 | 657 | }
|
665 | 658 |
|
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 | + } |
669 | 685 | }
|
670 | 686 | }
|
0 commit comments