@@ -2477,6 +2477,7 @@ public void copyCurrentEvent(JsonParser p) throws IOException
2477
2477
_copyCurrentIntValue (p );
2478
2478
break ;
2479
2479
case ID_NUMBER_FLOAT :
2480
+ // Different from "copyCurrentEventExact"!
2480
2481
_copyCurrentFloatValue (p );
2481
2482
break ;
2482
2483
case ID_TRUE :
@@ -2496,6 +2497,70 @@ public void copyCurrentEvent(JsonParser p) throws IOException
2496
2497
}
2497
2498
}
2498
2499
2500
+ /**
2501
+ * Same as {@link #copyCurrentEvent} with the exception that copying of numeric
2502
+ * values tries to avoid any conversion losses; in particular for floating-point
2503
+ * numbers. This usually matters when transcoding from textual format like JSON
2504
+ * to a binary format.
2505
+ * See {@link #_copyCurrentFloatValueExact} for details.
2506
+ *
2507
+ * @param p Parser that points to event (token) to copy
2508
+ *
2509
+ * @throws IOException if there is either an underlying I/O problem or encoding
2510
+ * issue at format layer
2511
+ *
2512
+ * @since 2.15
2513
+ */
2514
+ public void copyCurrentEventExact (JsonParser p ) throws IOException
2515
+ {
2516
+ JsonToken t = p .currentToken ();
2517
+ final int token = (t == null ) ? ID_NOT_AVAILABLE : t .id ();
2518
+ switch (token ) {
2519
+ case ID_NOT_AVAILABLE :
2520
+ _reportError ("No current event to copy" );
2521
+ break ; // never gets here
2522
+ case ID_START_OBJECT :
2523
+ writeStartObject ();
2524
+ break ;
2525
+ case ID_END_OBJECT :
2526
+ writeEndObject ();
2527
+ break ;
2528
+ case ID_START_ARRAY :
2529
+ writeStartArray ();
2530
+ break ;
2531
+ case ID_END_ARRAY :
2532
+ writeEndArray ();
2533
+ break ;
2534
+ case ID_FIELD_NAME :
2535
+ writeFieldName (p .getCurrentName ());
2536
+ break ;
2537
+ case ID_STRING :
2538
+ _copyCurrentStringValue (p );
2539
+ break ;
2540
+ case ID_NUMBER_INT :
2541
+ _copyCurrentIntValue (p );
2542
+ break ;
2543
+ case ID_NUMBER_FLOAT :
2544
+ // Different from "copyCurrentEvent"!
2545
+ _copyCurrentFloatValueExact (p );
2546
+ break ;
2547
+ case ID_TRUE :
2548
+ writeBoolean (true );
2549
+ break ;
2550
+ case ID_FALSE :
2551
+ writeBoolean (false );
2552
+ break ;
2553
+ case ID_NULL :
2554
+ writeNull ();
2555
+ break ;
2556
+ case ID_EMBEDDED_OBJECT :
2557
+ writeObject (p .getEmbeddedObject ());
2558
+ break ;
2559
+ default :
2560
+ throw new IllegalStateException ("Internal error: unknown current token, " +t );
2561
+ }
2562
+ }
2563
+
2499
2564
/**
2500
2565
* Method for copying contents of the current event
2501
2566
* <b>and following events that it encloses</b>
@@ -2525,6 +2590,11 @@ public void copyCurrentEvent(JsonParser p) throws IOException
2525
2590
* <b>last event</b> that was copied. This will either be
2526
2591
* the event parser already pointed to (if there were no
2527
2592
* enclosed events), or the last enclosed event copied.
2593
+ *<p>
2594
+ * NOTE: copying of individual tokens/events is handled by delegating
2595
+ * to {@link #copyCurrentEvent} method (make sure to read about difference
2596
+ * between that method and {@link #copyCurrentEventExact} for numeric
2597
+ * value accuracy).
2528
2598
*
2529
2599
* @param p Parser that points to the value to copy
2530
2600
*
0 commit comments