Skip to content

Commit b5a57eb

Browse files
committed
Fix #509 (add IonValueMapper.builder() overloads)
1 parent 294051d commit b5a57eb

File tree

3 files changed

+71
-7
lines changed

3 files changed

+71
-7
lines changed

ion/src/main/java/com/fasterxml/jackson/dataformat/ion/ionvalue/IonValueMapper.java

+65-7
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import com.fasterxml.jackson.dataformat.ion.EnumAsIonSymbolModule;
2222
import com.fasterxml.jackson.dataformat.ion.IonFactory;
2323
import com.fasterxml.jackson.dataformat.ion.IonObjectMapper;
24-
2524
import com.amazon.ion.IonSystem;
2625
import com.amazon.ion.IonValue;
26+
import com.amazon.ion.system.IonSystemBuilder;
2727

2828
/**
2929
* Supports serializing Ion to POJO and back using the Jackson Ion framework.
@@ -52,11 +52,27 @@ public IonValueMapper(IonSystem ionSystem) {
5252
this(ionSystem, null);
5353
}
5454

55-
// @since 2.18: needed for `copy()`
55+
/**
56+
* Needed for `copy()`
57+
*
58+
* @since 2.18
59+
*/
5660
protected IonValueMapper(IonValueMapper src) {
5761
super(src);
5862
}
5963

64+
/**
65+
* Needed for some builders
66+
*
67+
* @since 2.18
68+
*/
69+
protected IonValueMapper(IonFactory f, PropertyNamingStrategy strategy) {
70+
super(f);
71+
this.registerModule(new IonValueModule());
72+
this.registerModule(new EnumAsIonSymbolModule());
73+
this.setPropertyNamingStrategy(strategy);
74+
}
75+
6076
/**
6177
* Constructor that provides an override on the default Constructor for the PropertyNamingStrategy.
6278
*
@@ -66,19 +82,61 @@ protected IonValueMapper(IonValueMapper src) {
6682
* {@link PropertyNamingStrategy}
6783
*/
6884
public IonValueMapper(IonSystem ionSystem, PropertyNamingStrategy strategy) {
69-
super(new IonFactory(null, ionSystem));
70-
this.registerModule(new IonValueModule());
71-
this.registerModule(new EnumAsIonSymbolModule());
72-
this.setPropertyNamingStrategy(strategy);
85+
this(new IonFactory(null, ionSystem), strategy);
7386
}
7487

7588
/*
7689
/**********************************************************************
7790
/* Life-cycle, builders
91+
/*
92+
/* NOTE: must "override" (mask) all static methods from parent class
93+
/* (most of which just call basic `builder()` or `builder(IonSystem)`
7894
/**********************************************************************
7995
*/
8096

81-
// TODO: add overrides
97+
public static Builder builder() {
98+
return builder(IonSystemBuilder.standard().build());
99+
}
100+
101+
public static Builder builder(IonSystem ionSystem) {
102+
return builder(ionSystem, null);
103+
}
104+
105+
/**
106+
* Canonical {@code builder()} method that most other methods
107+
* ultimately call.
108+
*/
109+
public static Builder builder(IonSystem ionSystem, PropertyNamingStrategy strategy) {
110+
return new Builder(new IonValueMapper(ionSystem, strategy));
111+
}
112+
113+
public static Builder builderForBinaryWriters() {
114+
return builderForBinaryWriters(IonSystemBuilder.standard().build());
115+
}
116+
117+
public static Builder builderForBinaryWriters(IonSystem ionSystem) {
118+
return builder(IonFactory.builderForBinaryWriters()
119+
.ionSystem(ionSystem)
120+
.build());
121+
}
122+
123+
public static Builder builderForTextualWriters() {
124+
return builderForTextualWriters(IonSystemBuilder.standard().build());
125+
}
126+
127+
public static Builder builderForTextualWriters(IonSystem ionSystem) {
128+
return builder(IonFactory.builderForTextualWriters()
129+
.ionSystem(ionSystem)
130+
.build());
131+
}
132+
133+
public static Builder builder(IonFactory streamFactory) {
134+
return builder(streamFactory, null);
135+
}
136+
137+
public static Builder builder(IonFactory streamFactory, PropertyNamingStrategy strategy) {
138+
return new Builder(new IonValueMapper(streamFactory, strategy));
139+
}
82140

83141
/*
84142
/**********************************************************************

release-notes/CREDITS-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,7 @@ Joachim Lous (@jlous)
338338
* Requested #494: Avro Schema generation: allow mapping Java Enum properties to
339339
Avro String values
340340
(2.18.0)
341+
342+
Robert Noack (@mr-robert)
343+
* Reported #509: IonValueMapper.builder() not implemented, does not register modules
344+
(2.18.0)

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Active maintainers:
2424
(contributed by Michal F)
2525
#508: (avro) Ignore `specificData` field on serialization
2626
(contributed by @pjfanning)
27+
#509: IonValueMapper.builder() not implemented, does not register modules
28+
(reported by Robert N)
2729

2830
2.17.3 (not yet released)
2931

0 commit comments

Comments
 (0)