Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions avro/src/main/java/tools/jackson/dataformat/avro/AvroMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ public AvroFactory tokenStreamFactory() {
return (AvroFactory) _streamFactory;
}

/*
/**********************************************************************
/* Format-specific
/**********************************************************************
*/

public boolean isEnabled(AvroReadFeature f) {
return _deserializationConfig.hasFormatFeature(f);
}

public boolean isEnabled(AvroWriteFeature f) {
return _serializationConfig.hasFormatFeature(f);
}

/*
/**********************************************************************
/* Schema introspection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.ByteArrayOutputStream;

import org.junit.jupiter.api.Test;

import tools.jackson.core.FormatSchema;
import tools.jackson.core.StreamReadCapability;
import tools.jackson.core.StreamWriteFeature;
Expand All @@ -28,6 +30,7 @@ public String getSchemaType() {
/**********************************************************************
*/

@Test
public void testFactoryDefaults() throws Exception
{
assertTrue(MAPPER.tokenStreamFactory().isEnabled(AvroReadFeature.AVRO_BUFFERING));
Expand All @@ -38,25 +41,29 @@ public void testFactoryDefaults() throws Exception
assertFalse(MAPPER.tokenStreamFactory().canUseSchema(BOGUS_SCHEMA));
}

@Test
public void testParserDefaults() throws Exception
{
AvroParser p = (AvroParser) MAPPER.createParser(new byte[0]);
assertTrue(p.isEnabled(AvroReadFeature.AVRO_BUFFERING));
p.close();
try (AvroParser p = (AvroParser) MAPPER.createParser(new byte[0])) {
assertTrue(p.isEnabled(AvroReadFeature.AVRO_BUFFERING));
}

AvroMapper mapper = AvroMapper.builder()
.disable(AvroReadFeature.AVRO_BUFFERING)
.build();
p = (AvroParser) mapper.createParser(new byte[0]);
assertFalse(p.isEnabled(AvroReadFeature.AVRO_BUFFERING));

// 15-Jan-2021, tatu: 2.14 added this setting, not enabled in
// default set
assertTrue(p.streamReadCapabilities().isEnabled(StreamReadCapability.EXACT_FLOATS));
try (AvroParser p = (AvroParser) mapper.createParser(new byte[0])) {
assertFalse(p.isEnabled(AvroReadFeature.AVRO_BUFFERING));

// 15-Jan-2021, tatu: 2.14 added this setting, not enabled in
// default set
assertTrue(p.streamReadCapabilities().isEnabled(StreamReadCapability.EXACT_FLOATS));
}

p.close();
}
// [dataformats-binary#619]
assertTrue(MAPPER.isEnabled(AvroReadFeature.AVRO_BUFFERING));
}

@Test
public void testGeneratorDefaults() throws Exception
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Expand All @@ -76,6 +83,9 @@ public void testGeneratorDefaults() throws Exception
.createGenerator(bytes);
assertFalse(g.isEnabled(AvroWriteFeature.AVRO_BUFFERING));
g.close();

// [dataformats-binary#619]
assertFalse(MAPPER.isEnabled(AvroWriteFeature.AVRO_FILE_OUTPUT));
}

/*
Expand All @@ -84,6 +94,7 @@ public void testGeneratorDefaults() throws Exception
/**********************************************************************
*/

@Test
public void testDefaultSettingsWithAvroMapper()
{
AvroMapper mapper = new AvroMapper();
Expand Down
18 changes: 16 additions & 2 deletions cbor/src/main/java/tools/jackson/dataformat/cbor/CBORMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ protected Object readResolve() {
}

/*
/**********************************************************
/**********************************************************************
/* Life-cycle
/**********************************************************
/**********************************************************************
*/

public CBORMapper() {
Expand Down Expand Up @@ -173,6 +173,20 @@ public CBORFactory tokenStreamFactory() {
return (CBORFactory) _streamFactory;
}

/*
/**********************************************************************
/* Format-specific
/**********************************************************************
*/

public boolean isEnabled(CBORReadFeature f) {
return _deserializationConfig.hasFormatFeature(f);
}

public boolean isEnabled(CBORWriteFeature f) {
return _serializationConfig.hasFormatFeature(f);
}

/*
/**********************************************************
/* Helper class(es)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public enum CBORWriteFeature implements FormatFeature
* representation that is enough to retain value; if false, will use
* length indicated by argument type (4-byte for <code>int</code>,
* 8-byte for <code>long</code> and so on).
*<p>
* Default value is {@code true} meaning that minimal representation is used
* when encoding.
*/
WRITE_MINIMAL_INTS(true),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,12 @@ public void testNegativeBigIntegerWithoutLeadingZero() throws Exception {
assertEquals(BigInteger.ONE,
mapper2.readValue(encodedNegative, BigInteger.class));
}

// [dataformats-binary#619]
@Test
void testFormatFeatureDefaults() {
CBORMapper mapper = CBORMapper.shared();
assertTrue(mapper.isEnabled(CBORReadFeature.DECODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING));
assertTrue(mapper.isEnabled(CBORWriteFeature.WRITE_MINIMAL_INTS));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tools.jackson.databind.deser.DeserializationContextExt;
import tools.jackson.databind.module.SimpleModule;
import tools.jackson.databind.ser.SerializationContextExt;

import tools.jackson.dataformat.ion.ionvalue.IonValueModule;

import com.amazon.ion.IonDatagram;
Expand Down Expand Up @@ -276,6 +277,21 @@ public IonFactory tokenStreamFactory() {
return (IonFactory) _streamFactory;
}

/*
/**********************************************************************
/* Format-specific
/**********************************************************************
*/

public boolean isEnabled(IonReadFeature f) {
return _deserializationConfig.hasFormatFeature(f);
}

public boolean isEnabled(IonWriteFeature f) {
return _serializationConfig.hasFormatFeature(f);
}


/*
/************************************************************************
/* Additional convenience factory methods for parsers, generators
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package tools.jackson.dataformat.ion.misc;

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import tools.jackson.dataformat.ion.*;

public class FeatureDefaultsTest
{
// [dataformats-binary#619]
@Test
void testFormatFeatureDefaults() {
IonObjectMapper mapper = IonObjectMapper.shared();
assertTrue(mapper.isEnabled(IonReadFeature.USE_NATIVE_TYPE_ID));
assertTrue(mapper.isEnabled(IonWriteFeature.USE_NATIVE_TYPE_ID));
}
}
7 changes: 6 additions & 1 deletion release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Fawzi Essam (@iifawzi)
* Contributed #582: Change defaults for `CBORReadFeature.DECODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING`
and `CBORWriteFeature.ENCODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING` to `true` (enabled)
(3.0.0)
* Contribited #591: Change `CBOR` Features defaults for 3.0
* Contributed #591: Change `CBOR` Features defaults for 3.0
(3.0.0)

Andy Wilkinson (@wilkinsona)

* Requested #619: (avro, cbor, ion, smile) Add `isEnabled()` methods for format-specific features
(like `CBORReadFeature` and `CBORWriteFeature`) to mappers
(3.1.0)
6 changes: 6 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ implementations)
=== Releases ===
------------------------------------------------------------------------

3.1.0 (not yet released)

#619: (avro, cbor, ion, smile) Add `isEnabled()` methods for format-specific features
(like `CBORReadFeature` and `CBORWriteFeature`) to mappers
(requested by Andy W)

3.0.1 (21-Oct-2025)

No changes since 3.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ public SmileFactory tokenStreamFactory() {
return (SmileFactory) _streamFactory;
}

/*
/**********************************************************************
/* Format-specific
/**********************************************************************
*/

public boolean isEnabled(SmileReadFeature f) {
return _deserializationConfig.hasFormatFeature(f);
}

public boolean isEnabled(SmileWriteFeature f) {
return _serializationConfig.hasFormatFeature(f);
}

/*
/**********************************************************************
/* Helper class(es)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public enum SmileReadFeature implements FormatFeature
* or optional. If enabled, it means that only input that starts with the header
* is accepted as valid; if disabled, header is optional. In latter case,
* settings for content are assumed to be defaults.
*<p>
* Feature is enabled by default.
*/
REQUIRE_HEADER(true)
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import org.junit.jupiter.api.Test;

import tools.jackson.databind.*;
import tools.jackson.dataformat.smile.BaseTestForSmile;
import tools.jackson.dataformat.smile.SmileFactory;
import tools.jackson.dataformat.smile.SmileMapper;

import tools.jackson.dataformat.smile.*;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class MapperFeaturesTest extends BaseTestForSmile
{
static class Bean {
public static class Bean {
public int value;
}

Expand All @@ -35,4 +35,12 @@ public void testIndent() throws Exception
Bean result = mapper.readValue(smile, 0, smile.length, Bean.class);
assertEquals(42, result.value);
}

// [dataformats-binary#619]
@Test
void testFormatFeatureDefaults() {
SmileMapper mapper = SmileMapper.shared();
assertTrue(mapper.isEnabled(SmileReadFeature.REQUIRE_HEADER));
assertTrue(mapper.isEnabled(SmileWriteFeature.WRITE_HEADER));
}
}