Skip to content

Commit b23bc2e

Browse files
committed
Allow disabling native type ids in IonMapper
This change makes the behavior of the Ion format more similar to YAMLMapper in `jackson-dataformat-yaml`. * Native type ids may be disabled in `Ion{Generator,Factory,Mapper}` * IonParser capability introspection `canReadTypeId => true` * IonGenerator#writeTypePrefix override removed, enabling non-native Together these changes allow `AsPropertyDeserializer` with an `IonParser` backing to deserialize either style while the `IonGenerator` will honor its constructed feature set.
1 parent d8c902e commit b23bc2e

File tree

7 files changed

+484
-88
lines changed

7 files changed

+484
-88
lines changed

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

+124-7
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,31 @@ public class IonFactory extends JsonFactory {
5656
* Whether we will produce binary or text Ion writers: default is textual.
5757
*/
5858
protected boolean _cfgCreateBinaryWriters = false;
59-
59+
60+
/**
61+
* Bitfield (set of flags) of all parser features that are enabled
62+
* by default.
63+
*/
64+
protected final static int DEFAULT_ION_PARSER_FEATURE_FLAGS = IonParser.Feature.collectDefaults();
65+
66+
/**
67+
* Bitfield (set of flags) of all generator features that are enabled
68+
* by default.
69+
*/
70+
protected final static int DEFAULT_ION_GENERATOR_FEATURE_FLAGS = IonGenerator.Feature.collectDefaults();
71+
72+
protected int _ionParserFeatures = DEFAULT_ION_PARSER_FEATURE_FLAGS;
73+
74+
protected int _ionGeneratorFeatures = DEFAULT_ION_GENERATOR_FEATURE_FLAGS;
75+
6076
public IonFactory() {
6177
this((ObjectCodec) null);
6278
}
6379

6480
public IonFactory(ObjectCodec mapper) {
6581
this(mapper, IonSystemBuilder.standard().build());
6682
}
67-
83+
6884
public IonFactory(ObjectCodec mapper, IonSystem system) {
6985
super(mapper);
7086
_system = system;
@@ -110,7 +126,7 @@ public static IonFactory forBinaryWriters() {
110126
public static IonFactoryBuilder builderForBinaryWriters() {
111127
return new IonFactoryBuilder(true);
112128
}
113-
129+
114130
/**
115131
* Method for creating {@link IonFactory} that will
116132
* create textual (not binary) writers.
@@ -144,7 +160,7 @@ public Version version() {
144160
public String getFormatName() {
145161
return FORMAT_NAME_ION;
146162
}
147-
163+
148164
public void setCreateBinaryWriters(boolean b) {
149165
_cfgCreateBinaryWriters = b;
150166
}
@@ -164,6 +180,107 @@ public boolean canUseCharArrays() {
164180
return false;
165181
}
166182

183+
/*
184+
/**********************************************************
185+
/* Configuration, parser settings
186+
/**********************************************************
187+
*/
188+
189+
/**
190+
* Method for enabling or disabling specified parser feature
191+
* (check {@link IonParser.Feature} for list of features)
192+
*/
193+
public final IonFactory configure(IonParser.Feature f, boolean state)
194+
{
195+
if (state) {
196+
enable(f);
197+
} else {
198+
disable(f);
199+
}
200+
return this;
201+
}
202+
203+
/**
204+
* Method for enabling specified parser feature
205+
* (check {@link IonParser.Feature} for list of features)
206+
*/
207+
public IonFactory enable(IonParser.Feature f) {
208+
_ionParserFeatures |= f.getMask();
209+
return this;
210+
}
211+
212+
/**
213+
* Method for disabling specified parser features
214+
* (check {@link IonParser.Feature} for list of features)
215+
*/
216+
public IonFactory disable(IonParser.Feature f) {
217+
_ionParserFeatures &= ~f.getMask();
218+
return this;
219+
}
220+
221+
/**
222+
* Checked whether specified parser feature is enabled.
223+
*/
224+
public final boolean isEnabled(IonParser.Feature f) {
225+
return (_ionParserFeatures & f.getMask()) != 0;
226+
}
227+
228+
@Override
229+
public int getFormatParserFeatures() {
230+
return _ionParserFeatures;
231+
}
232+
233+
/*
234+
/**********************************************************
235+
/* Configuration, generator settings
236+
/**********************************************************
237+
*/
238+
239+
/**
240+
* Method for enabling or disabling specified generator feature
241+
* (check {@link IonGenerator.Feature} for list of features)
242+
*/
243+
public final IonFactory configure(IonGenerator.Feature f, boolean state) {
244+
if (state) {
245+
enable(f);
246+
} else {
247+
disable(f);
248+
}
249+
return this;
250+
}
251+
252+
253+
/**
254+
* Method for enabling specified generator features
255+
* (check {@link IonGenerator.Feature} for list of features)
256+
*/
257+
public IonFactory enable(IonGenerator.Feature f) {
258+
_ionGeneratorFeatures |= f.getMask();
259+
return this;
260+
}
261+
262+
/**
263+
* Method for disabling specified generator feature
264+
* (check {@link IonGenerator.Feature} for list of features)
265+
*/
266+
public IonFactory disable(IonGenerator.Feature f) {
267+
_ionGeneratorFeatures &= ~f.getMask();
268+
return this;
269+
}
270+
271+
/**
272+
* Check whether specified generator feature is enabled.
273+
*/
274+
public final boolean isEnabled(IonGenerator.Feature f) {
275+
return (_ionGeneratorFeatures & f.getMask()) != 0;
276+
}
277+
278+
@Override
279+
public int getFormatGeneratorFeatures() {
280+
return _ionGeneratorFeatures;
281+
}
282+
283+
167284
/*
168285
***************************************************************
169286
* Extended API
@@ -305,7 +422,7 @@ protected String _readAll(Reader r, IOContext ctxt) throws IOException
305422

306423
main_loop:
307424
while (true) {
308-
425+
309426
while (offset < buf.length) {
310427
int count = r.read(buf, offset, buf.length - offset);
311428
if (count < 0) {
@@ -355,6 +472,6 @@ protected IonGenerator _createGenerator(OutputStream out, JsonEncoding enc, bool
355472

356473
protected IonGenerator _createGenerator(IonWriter ion, boolean ionWriterIsManaged, IOContext ctxt, Closeable dst)
357474
{
358-
return new IonGenerator(_generatorFeatures, _objectCodec, ion, ionWriterIsManaged, ctxt, dst);
359-
}
475+
return new IonGenerator(_generatorFeatures, _ionGeneratorFeatures, _objectCodec, ion, ionWriterIsManaged, ctxt, dst);
476+
}
360477
}

0 commit comments

Comments
 (0)