diff --git a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/ionvalue/IonValueMapper.java b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/ionvalue/IonValueMapper.java index e2f103bf9..95e837d13 100644 --- a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/ionvalue/IonValueMapper.java +++ b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/ionvalue/IonValueMapper.java @@ -24,6 +24,7 @@ import com.amazon.ion.IonSystem; import com.amazon.ion.IonValue; +import com.amazon.ion.system.IonSystemBuilder; /** * Supports serializing Ion to POJO and back using the Jackson Ion framework. @@ -52,11 +53,27 @@ public IonValueMapper(IonSystem ionSystem) { this(ionSystem, null); } - // @since 2.18: needed for `copy()` + /** + * Needed for `copy()` + * + * @since 2.18 + */ protected IonValueMapper(IonValueMapper src) { super(src); } + /** + * Needed for some builders + * + * @since 2.18 + */ + protected IonValueMapper(IonFactory f, PropertyNamingStrategy strategy) { + super(f); + this.registerModule(new IonValueModule()); + this.registerModule(new EnumAsIonSymbolModule()); + this.setPropertyNamingStrategy(strategy); + } + /** * Constructor that provides an override on the default Constructor for the PropertyNamingStrategy. * @@ -66,19 +83,61 @@ protected IonValueMapper(IonValueMapper src) { * {@link PropertyNamingStrategy} */ public IonValueMapper(IonSystem ionSystem, PropertyNamingStrategy strategy) { - super(new IonFactory(null, ionSystem)); - this.registerModule(new IonValueModule()); - this.registerModule(new EnumAsIonSymbolModule()); - this.setPropertyNamingStrategy(strategy); + this(new IonFactory(null, ionSystem), strategy); } /* /********************************************************************** /* Life-cycle, builders + /* + /* NOTE: must "override" (mask) all static methods from parent class + /* (most of which just call basic `builder()` or `builder(IonSystem)` /********************************************************************** */ - // TODO: add overrides + public static Builder builder() { + return builder(IonSystemBuilder.standard().build()); + } + + public static Builder builder(IonSystem ionSystem) { + return builder(ionSystem, null); + } + + /** + * Canonical {@code builder()} method that most other methods + * ultimately call. + */ + public static Builder builder(IonSystem ionSystem, PropertyNamingStrategy strategy) { + return new Builder(new IonValueMapper(ionSystem, strategy)); + } + + public static Builder builderForBinaryWriters() { + return builderForBinaryWriters(IonSystemBuilder.standard().build()); + } + + public static Builder builderForBinaryWriters(IonSystem ionSystem) { + return builder(IonFactory.builderForBinaryWriters() + .ionSystem(ionSystem) + .build()); + } + + public static Builder builderForTextualWriters() { + return builderForTextualWriters(IonSystemBuilder.standard().build()); + } + + public static Builder builderForTextualWriters(IonSystem ionSystem) { + return builder(IonFactory.builderForTextualWriters() + .ionSystem(ionSystem) + .build()); + } + + public static Builder builder(IonFactory streamFactory) { + return builder(streamFactory, null); + } + + public static Builder builder(IonFactory streamFactory, PropertyNamingStrategy strategy) { + return new Builder(new IonValueMapper(streamFactory, strategy)); + } /* /********************************************************************** diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/ionvalue/IonValueMapperTest.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/ionvalue/IonValueMapperTest.java index fdcd50218..fbeba4951 100644 --- a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/ionvalue/IonValueMapperTest.java +++ b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/ionvalue/IonValueMapperTest.java @@ -50,8 +50,8 @@ */ public class IonValueMapperTest { private final IonSystem ionSystem = IonSystemBuilder.standard().build(); - private final IonValueMapper ionValueMapper = new IonValueMapper(ionSystem, - PropertyNamingStrategies.SNAKE_CASE); + private final IonValueMapper ionValueMapper = (IonValueMapper) IonValueMapper.builder(ionSystem, + PropertyNamingStrategies.SNAKE_CASE).build(); enum ReturnCode { Success, @@ -252,4 +252,16 @@ private void assertRoundTrip(String ion, Class clazz) throws IOException { IonValue actual = ionValueMapper.serialize(o); assertEquals(expected, actual); } + + // for [dataformats-binary#509] + @Test + public void testBuilders() throws Exception { + IonObjectMapper mapper = IonValueMapper.builder().build(); + assertNotNull(mapper); + assertEquals(IonValueMapper.class, mapper.getClass()); + + mapper = IonValueMapper.builder(ionSystem).build(); + assertNotNull(mapper); + assertEquals(IonValueMapper.class, mapper.getClass()); + } } diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 2c1760e6e..8430cd469 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -338,3 +338,7 @@ Joachim Lous (@jlous) * Requested #494: Avro Schema generation: allow mapping Java Enum properties to Avro String values (2.18.0) + +Robert Noack (@mr-robert) + * Reported #509: IonValueMapper.builder() not implemented, does not register modules + (2.18.0) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index e57ac1106..3d2686002 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -24,6 +24,8 @@ Active maintainers: (contributed by Michal F) #508: (avro) Ignore `specificData` field on serialization (contributed by @pjfanning) +#509: IonValueMapper.builder() not implemented, does not register modules + (reported by Robert N) 2.17.3 (not yet released)