@@ -227,12 +227,10 @@ public static JsonPointer forPath(JsonStreamContext context,
227
227
}
228
228
approxLength += 2 + propName .length ();
229
229
next = new PointerSegment (next , propName , -1 );
230
- // tail = new JsonPointer(_fullPath(tail, seg), 0, seg, tail);
231
230
} else if (context .inArray () || includeRoot ) {
232
231
int ix = context .getCurrentIndex ();
233
232
approxLength += 6 ;
234
233
next = new PointerSegment (next , null , ix );
235
- // tail = new JsonPointer(_fullPath(tail, ixStr), 0, ixStr, ix, tail);
236
234
}
237
235
// NOTE: this effectively drops ROOT node(s); should have 1 such node,
238
236
// as the last one, but we don't have to care (probably some paths have
@@ -244,7 +242,6 @@ public static JsonPointer forPath(JsonStreamContext context,
244
242
245
243
// And here the fun starts! We have the head, need to traverse
246
244
// to compose full path String
247
- // final PointerSegment head = next;
248
245
StringBuilder pathBuilder = new StringBuilder (approxLength );
249
246
PointerSegment last = null ;
250
247
@@ -295,29 +292,7 @@ private static void _appendEscaped(StringBuilder sb, String segment)
295
292
sb .append (c );
296
293
}
297
294
}
298
-
299
- /* Factory method that composes a pointer instance, given a set
300
- * of 'raw' segments: raw meaning that no processing will be done,
301
- * no escaping may is present.
302
- *
303
- * @param segments
304
- *
305
- * @return Constructed path instance
306
- */
307
- /* TODO!
308
- public static JsonPointer fromSegment(String... segments)
309
- {
310
- if (segments.length == 0) {
311
- return EMPTY;
312
- }
313
- JsonPointer prev = null;
314
-
315
- for (String segment : segments) {
316
- JsonPointer next = new JsonPointer()
317
- }
318
- }
319
- */
320
-
295
+
321
296
/*
322
297
/**********************************************************
323
298
/* Public API
@@ -575,7 +550,7 @@ public JsonPointer head() {
575
550
576
551
/*
577
552
/**********************************************************
578
- /* Standard method overrides
553
+ /* Standard method overrides (since 2.14)
579
554
/**********************************************************
580
555
*/
581
556
@@ -853,38 +828,42 @@ public PointerSegment(PointerSegment next, String pn, int ix) {
853
828
854
829
// Since 2.14: needed for efficient JDK serializability
855
830
private Object writeReplace () {
856
- return new Serialization (_asString );
831
+ // 11-Oct-2022, tatu: very important, must serialize just contents!
832
+ return new Serialization (toString ());
857
833
}
858
834
859
835
/**
860
836
* This must only exist to allow both final properties and implementation of
861
- * Externalizable/Serializable for JsonPointer
837
+ * Externalizable/Serializable for JsonPointer.
838
+ * Note that here we do not store offset but simply use (and expect use)
839
+ * full path, from which we need to decode actual structure.
862
840
*
863
841
* @since 2.14
864
842
*/
865
843
static class Serialization implements Externalizable
866
844
{
867
- private String _asString ;
845
+ private String _fullPath ;
868
846
869
847
public Serialization () { }
870
848
871
- Serialization (String asString ) {
872
- _asString = asString ;
849
+ Serialization (String fullPath ) {
850
+ _fullPath = fullPath ;
873
851
}
874
852
875
853
@ Override
876
854
public void writeExternal (ObjectOutput out ) throws IOException {
877
- out .writeUTF (_asString );
855
+ out .writeUTF (_fullPath );
878
856
}
879
857
880
858
@ Override
881
859
public void readExternal (ObjectInput in ) throws IOException , ClassNotFoundException {
882
- _asString = in .readUTF ();
860
+ _fullPath = in .readUTF ();
883
861
}
884
862
885
863
private Object readResolve () throws ObjectStreamException {
886
- // NOTE: method handles canonicalization of "empty":
887
- return compile (_asString );
864
+ // NOTE: method handles canonicalization of "empty", as well as other
865
+ // aspects of decoding.
866
+ return compile (_fullPath );
888
867
}
889
868
}
890
869
}
0 commit comments