25
25
import com .fasterxml .jackson .core .JsonGenerationException ;
26
26
import com .fasterxml .jackson .core .JsonGenerator ;
27
27
import com .fasterxml .jackson .core .JsonProcessingException ;
28
+ import com .fasterxml .jackson .core .JsonToken ;
28
29
import com .fasterxml .jackson .core .ObjectCodec ;
29
30
import com .fasterxml .jackson .core .Version ;
30
31
import com .fasterxml .jackson .core .base .GeneratorBase ;
31
32
import com .fasterxml .jackson .core .io .IOContext ;
32
33
import com .fasterxml .jackson .core .json .JsonWriteContext ;
34
+ import com .fasterxml .jackson .core .type .WritableTypeId ;
33
35
import com .fasterxml .jackson .dataformat .ion .polymorphism .IonAnnotationTypeSerializer ;
34
36
35
37
import software .amazon .ion .IonType ;
@@ -120,10 +122,22 @@ public boolean isClosed() {
120
122
}
121
123
122
124
/*
123
- *****************************************************************
124
- * JsonGenerator implementation: write numeric values
125
- *****************************************************************
126
- */
125
+ /*****************************************************************
126
+ /* Capability introspection
127
+ /*****************************************************************
128
+ */
129
+
130
+ @ Override
131
+ public boolean canWriteTypeId () { return true ; }
132
+
133
+ @ Override
134
+ public boolean canWriteBinaryNatively () { return true ; }
135
+
136
+ /*
137
+ /*****************************************************************
138
+ /* JsonGenerator implementation: write numeric values
139
+ /*****************************************************************
140
+ */
127
141
128
142
@ Override
129
143
public void writeNumber (int value ) throws IOException , JsonGenerationException {
@@ -336,10 +350,10 @@ public void writeValue(Timestamp value) throws IOException {
336
350
}
337
351
338
352
/*
339
- *****************************************************************
340
- * Methods base impl needs
341
- *****************************************************************
342
- */
353
+ / *****************************************************************
354
+ / * Methods base impl needs
355
+ / *****************************************************************
356
+ */
343
357
344
358
@ Override
345
359
protected void _releaseBuffers () {
@@ -424,9 +438,48 @@ public void writeStartObject() throws IOException, JsonGenerationException {
424
438
}
425
439
426
440
/*
427
- *****************************************************************
428
- * Standard methods
429
- *****************************************************************
441
+ /*****************************************************************
442
+ /* Support for type ids
443
+ /*****************************************************************
444
+ */
445
+
446
+ @ Override
447
+ public void writeTypeId (Object rawId ) throws IOException {
448
+ if (rawId instanceof String []) {
449
+ String [] ids = (String []) rawId ;
450
+ for (String id : ids ) {
451
+ annotateNextValue (id );
452
+ }
453
+ } else {
454
+ annotateNextValue (String .valueOf (rawId ));
455
+ }
456
+ }
457
+
458
+ // default might actually work, but let's straighten it out a bit
459
+ @ Override
460
+ public WritableTypeId writeTypePrefix (WritableTypeId typeIdDef ) throws IOException
461
+ {
462
+ final JsonToken valueShape = typeIdDef .valueShape ;
463
+ typeIdDef .wrapperWritten = false ;
464
+ writeTypeId (typeIdDef .id );
465
+
466
+ // plus start marker for value, if/as necessary
467
+ if (valueShape == JsonToken .START_OBJECT ) {
468
+ writeStartObject (typeIdDef .forValue );
469
+ } else if (valueShape == JsonToken .START_ARRAY ) {
470
+ // should we now set the current object?
471
+ writeStartArray ();
472
+ }
473
+ return typeIdDef ;
474
+ }
475
+
476
+ // Default impl should work fine here:
477
+ // public WritableTypeId writeTypeSuffix(WritableTypeId typeIdDef) throws IOException
478
+
479
+ /*
480
+ /*****************************************************************
481
+ /* Standard methods
482
+ *****************************************************************
430
483
*/
431
484
432
485
@ Override
@@ -435,9 +488,9 @@ public String toString() {
435
488
}
436
489
437
490
/*
438
- *****************************************************************
439
- * Internal helper methods
440
- *****************************************************************
491
+ / *****************************************************************
492
+ / * Internal helper methods
493
+ / *****************************************************************
441
494
*/
442
495
443
496
protected void _reportNoRaw () throws IOException {
0 commit comments