Skip to content

Commit 6269303

Browse files
committed
Fixes to Ion backend to work with rewritten type-id handler
1 parent 0c9ed28 commit 6269303

File tree

3 files changed

+156
-156
lines changed

3 files changed

+156
-156
lines changed

ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonGenerator.java

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
import com.fasterxml.jackson.core.JsonGenerationException;
2626
import com.fasterxml.jackson.core.JsonGenerator;
2727
import com.fasterxml.jackson.core.JsonProcessingException;
28+
import com.fasterxml.jackson.core.JsonToken;
2829
import com.fasterxml.jackson.core.ObjectCodec;
2930
import com.fasterxml.jackson.core.Version;
3031
import com.fasterxml.jackson.core.base.GeneratorBase;
3132
import com.fasterxml.jackson.core.io.IOContext;
3233
import com.fasterxml.jackson.core.json.JsonWriteContext;
34+
import com.fasterxml.jackson.core.type.WritableTypeId;
3335
import com.fasterxml.jackson.dataformat.ion.polymorphism.IonAnnotationTypeSerializer;
3436

3537
import software.amazon.ion.IonType;
@@ -120,10 +122,22 @@ public boolean isClosed() {
120122
}
121123

122124
/*
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+
*/
127141

128142
@Override
129143
public void writeNumber(int value) throws IOException, JsonGenerationException {
@@ -336,10 +350,10 @@ public void writeValue(Timestamp value) throws IOException {
336350
}
337351

338352
/*
339-
*****************************************************************
340-
* Methods base impl needs
341-
*****************************************************************
342-
*/
353+
/*****************************************************************
354+
/* Methods base impl needs
355+
/*****************************************************************
356+
*/
343357

344358
@Override
345359
protected void _releaseBuffers() {
@@ -424,9 +438,48 @@ public void writeStartObject() throws IOException, JsonGenerationException {
424438
}
425439

426440
/*
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+
*****************************************************************
430483
*/
431484

432485
@Override
@@ -435,9 +488,9 @@ public String toString() {
435488
}
436489

437490
/*
438-
*****************************************************************
439-
* Internal helper methods
440-
*****************************************************************
491+
/*****************************************************************
492+
/* Internal helper methods
493+
/*****************************************************************
441494
*/
442495

443496
protected void _reportNoRaw() throws IOException {

0 commit comments

Comments
 (0)