diff --git a/ion/pom.xml b/ion/pom.xml index 5a76226b5..928417912 100644 --- a/ion/pom.xml +++ b/ion/pom.xml @@ -39,7 +39,7 @@ tree model) com.amazon.ion ion-java - 1.11.7 + 1.11.8-SNAPSHOT diff --git a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonFactory.java b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonFactory.java index 0c7843af8..2590d3c14 100644 --- a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonFactory.java +++ b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonFactory.java @@ -24,6 +24,7 @@ import java.io.Reader; import java.io.Writer; +import com.amazon.ion.IonEncodingVersion; import com.fasterxml.jackson.core.JsonEncoding; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; @@ -462,7 +463,11 @@ protected IonGenerator _createGenerator(OutputStream out, JsonEncoding enc, bool // Binary writers are simpler: no alternate encodings if (createBinaryWriters()) { ctxt.setEncoding(enc); - ion = _system.newBinaryWriter(out); + if (IonGenerator.Feature.ION_VERSION_1_1.enabledIn(_ionGeneratorFeatures)) { + ion = IonEncodingVersion.ION_1_1.binaryWriterBuilder().build(out); + } else { + ion = _system.newBinaryWriter(out); + } dst = out; } else { if (enc != JsonEncoding.UTF8) { // not sure if non-UTF-8 encodings would be legal... @@ -472,9 +477,14 @@ protected IonGenerator _createGenerator(OutputStream out, JsonEncoding enc, bool // In practice we seem to be better off using Jackson's efficient buffering encoder ctxt.setEncoding(enc); - Writer w = new UTF8Writer(ctxt, out); - ion = _system.newTextWriter(w); - dst = w; + if (IonGenerator.Feature.ION_VERSION_1_1.enabledIn(_ionGeneratorFeatures)) { + // TODO use IonEncodingVersion.ION_1_1 to create a text writer builder + throw new UnsupportedOperationException("Cannot yet create an Ion 1.1 text writer."); + } else { + Writer w = new UTF8Writer(ctxt, out); + ion = _system.newTextWriter(w); + dst = w; + } } return _createGenerator(ion, true, ctxt, dst); } diff --git a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonGenerator.java b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonGenerator.java index 5207a31ee..6a56c2cdd 100644 --- a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonGenerator.java +++ b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonGenerator.java @@ -66,6 +66,13 @@ public enum Feature implements FormatFeature // since 2.12 * @since 2.12 */ USE_NATIVE_TYPE_ID(true), + + /** + * Whether to use the Ion 1.1 encoding (true) or the Ion 1.0 encoding (false). Disabled by default. + * + * @since 2.18 // TODO change according to the minor version this lands in. + */ + ION_VERSION_1_1(false), ; protected final boolean _defaultState; diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/DataBindRoundtripTest.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/DataBindRoundtripTest.java index 1ec062cc0..536668192 100644 --- a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/DataBindRoundtripTest.java +++ b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/DataBindRoundtripTest.java @@ -187,6 +187,17 @@ Bean roundTrip(IonObjectMapper m, Bean bean) throws IOException { return m.readValue(data, 0, data.length, Bean.class); } }, + BINARY_1_1 { + @Override + Bean roundTrip(IonObjectMapper m, Bean bean) throws IOException { + m.setCreateBinaryWriters(true); + m.configure(IonGenerator.Feature.ION_VERSION_1_1, true); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + m.writeValue(out, bean); + byte[] data = out.toByteArray(); + return m.readValue(data, 0, data.length, Bean.class); + } + }, TEXT { @Override Bean roundTrip(IonObjectMapper m, Bean bean) throws IOException { diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/SimpleIonWriteTest.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/SimpleIonWriteTest.java index ce4e9dee3..57ec58e6f 100644 --- a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/SimpleIonWriteTest.java +++ b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/SimpleIonWriteTest.java @@ -46,11 +46,13 @@ public void testSimpleStructWriteText() throws Exception gen.close(); } - @Test - public void testSimpleStructWriteBinary() throws Exception + private void testSimpleStructWriteBinary(boolean enableIon11) throws Exception { IonFactory f = new IonFactory(); f.setCreateBinaryWriters(true); + if (enableIon11) { + f.configure(IonGenerator.Feature.ION_VERSION_1_1, true); + } ByteArrayOutputStream bos = new ByteArrayOutputStream(); JsonGenerator gen = f.createGenerator(bos); _writeSimple(gen); @@ -60,6 +62,18 @@ public void testSimpleStructWriteBinary() throws Exception gen.close(); } + @Test + public void testSimpleStructWriteBinary_1_0() throws Exception + { + testSimpleStructWriteBinary(false); + } + + @Test + public void testSimpleStructWriteBinary_1_1() throws Exception + { + testSimpleStructWriteBinary(true); + } + /** * There were some problems with flushing (or lack thereof), so let's * see that outputting using an encoding stream also works ok