Skip to content

Commit 3e14f2c

Browse files
committed
Implement #819; now configuration of FormatFeatures should work, but needs to be tested for CSV (for example)
1 parent b775489 commit 3e14f2c

File tree

6 files changed

+293
-46
lines changed

6 files changed

+293
-46
lines changed

release-notes/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Project: jackson-databind
66

77
2.7.0 (not yet released)
88

9+
#819: Add support for setting `FormatFeature` via `ObjectReader`, `ObjectWriter`
910
#918: Add `MapperFeature.ALLOW_EXPLICIT_PROPERTY_RENAMING`
1011
(contributed by David H)
1112
#933:Close some gaps to allow using the tryToResolveUnresolved flows

src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,14 +717,13 @@ public DeserializationConfig withNoProblemHandlers() {
717717
*/
718718
public void initialize(JsonParser p) {
719719
if (_parserFeaturesToChange != 0) {
720-
int orig = p.getFeatureMask();
721-
int newFlags = (orig & ~_parserFeaturesToChange) | _parserFeatures;
722-
if (orig != newFlags) {
723-
p.setFeatureMask(newFlags);
724-
}
720+
p.overrideStdFeatures(_parserFeatures, _parserFeaturesToChange);
721+
}
722+
if (_formatReadFeaturesToChange != 0) {
723+
p.overrideFormatFeatures(_formatReadFeatures, _formatReadFeaturesToChange);
725724
}
726725
}
727-
726+
728727
/*
729728
/**********************************************************
730729
/* MapperConfig implementation

src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3770,9 +3770,8 @@ protected JsonToken _initForReading(JsonParser p) throws IOException
37703770
// and then we must get something...
37713771
t = p.nextToken();
37723772
if (t == null) {
3773-
/* [JACKSON-546] Throw mapping exception, since it's failure to map,
3774-
* not an actual parsing problem
3775-
*/
3773+
// Throw mapping exception, since it's failure to map,
3774+
// not an actual parsing problem
37763775
throw JsonMappingException.from(p, "No content to map due to end-of-input");
37773776
}
37783777
}

src/main/java/com/fasterxml/jackson/databind/ObjectReader.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,65 @@ public ObjectReader withoutFeatures(JsonParser.Feature... features) {
475475
return _with(_config.withoutFeatures(features));
476476
}
477477

478+
/*
479+
/**********************************************************
480+
/* Life-cycle, fluent factory methods for FormatFeature (2.7)
481+
/**********************************************************
482+
*/
483+
484+
/**
485+
* Method for constructing a new reader instance that is configured
486+
* with specified feature enabled.
487+
*
488+
* @since 2.7
489+
*/
490+
public ObjectReader with(FormatFeature feature) {
491+
return _with(_config.with(feature));
492+
}
493+
494+
/**
495+
* Method for constructing a new reader instance that is configured
496+
* with specified features enabled.
497+
*
498+
* @since 2.7
499+
*/
500+
public ObjectReader withFeatures(FormatFeature... features) {
501+
return _with(_config.withFeatures(features));
502+
}
503+
504+
/**
505+
* Method for constructing a new reader instance that is configured
506+
* with specified feature disabled.
507+
*
508+
* @since 2.7
509+
*/
510+
public ObjectReader without(FormatFeature feature) {
511+
return _with(_config.without(feature));
512+
}
513+
514+
/**
515+
* Method for constructing a new reader instance that is configured
516+
* with specified features disabled.
517+
*
518+
* @since 2.7
519+
*/
520+
public ObjectReader withoutFeatures(FormatFeature... features) {
521+
return _with(_config.withoutFeatures(features));
522+
}
523+
478524
/*
479525
/**********************************************************
480526
/* Life-cycle, fluent factory methods, other
481527
/**********************************************************
482528
*/
483529

530+
/**
531+
* Mutant factory method that will construct a new instance that has
532+
* specified underlying {@link DeserializationConfig}.
533+
*<p>
534+
* NOTE: use of this method is not recommended, as there are many other
535+
* re-configuration methods available.
536+
*/
484537
public ObjectReader with(DeserializationConfig config) {
485538
return _with(config);
486539
}

src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public ObjectWriter withoutFeatures(SerializationFeature... features) {
314314

315315
/*
316316
/**********************************************************
317-
/* Life-cycle, fluent factories for JsonGenerator.Feature
317+
/* Life-cycle, fluent factories for JsonGenerator.Feature (2.5)
318318
/**********************************************************
319319
*/
320320

@@ -350,6 +350,44 @@ public ObjectWriter withoutFeatures(JsonGenerator.Feature... features) {
350350
return (newConfig == _config) ? this : _new(this, newConfig);
351351
}
352352

353+
/*
354+
/**********************************************************
355+
/* Life-cycle, fluent factories for FormatFeature (2.7)
356+
/**********************************************************
357+
*/
358+
359+
/**
360+
* @since 2.7
361+
*/
362+
public ObjectWriter with(FormatFeature feature) {
363+
SerializationConfig newConfig = _config.with(feature);
364+
return (newConfig == _config) ? this : _new(this, newConfig);
365+
}
366+
367+
/**
368+
* @since 2.7
369+
*/
370+
public ObjectWriter withFeatures(FormatFeature... features) {
371+
SerializationConfig newConfig = _config.withFeatures(features);
372+
return (newConfig == _config) ? this : _new(this, newConfig);
373+
}
374+
375+
/**
376+
* @since 2.7
377+
*/
378+
public ObjectWriter without(FormatFeature feature) {
379+
SerializationConfig newConfig = _config.without(feature);
380+
return (newConfig == _config) ? this : _new(this, newConfig);
381+
}
382+
383+
/**
384+
* @since 2.7
385+
*/
386+
public ObjectWriter withoutFeatures(FormatFeature... features) {
387+
SerializationConfig newConfig = _config.withoutFeatures(features);
388+
return (newConfig == _config) ? this : _new(this, newConfig);
389+
}
390+
353391
/*
354392
/**********************************************************
355393
/* Life-cycle, fluent factories, type-related

0 commit comments

Comments
 (0)