diff --git a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactory.java b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactory.java index 93a58af7c..2f6c376a9 100644 --- a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactory.java +++ b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactory.java @@ -179,12 +179,10 @@ public boolean canUseSchema(FormatSchema schema) { return false; // no (mandatory) FormatSchema for cbor } - // No Reader features yet for CBOR - /*@Override + @Override public Class getFormatReadFeatureType() { return CBORReadFeature.class; } - */ @Override public Class getFormatWriteFeatureType() { diff --git a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORReadFeature.java b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORReadFeature.java index 78cc7251e..c6ab0a8e8 100644 --- a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORReadFeature.java +++ b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORReadFeature.java @@ -16,16 +16,16 @@ public enum CBORReadFeature implements FormatFeature * or the legacy Jackson encoding logic (encoding up to Jackson 2.19). * When enabled, ensures proper encoding of negative values * (e.g., {@code [0xC3, 0x41, 0x00]} is decoded as -1) - * When disabled, maintains backwards compatibility with existing implementations + * When disabled, maintains compatible behavior to versions prior to 3.0. * (e.g., {@code [0xC3, 0x41, 0x00]} is decoded as 0). *

* Note that there is the counterpart * {@link CBORWriteFeature#ENCODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING} * for encoding. *

- * The default value is {@code false} for backwards compatibility. + * The default value is {@code true} in Jackson 3.x (was {@code false} in Jackson 2.x). */ - DECODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING(false), + DECODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING(true), /** * Feature that determines how an {@code undefined} value ({@code 0xF7}) is exposed @@ -34,11 +34,11 @@ public enum CBORReadFeature implements FormatFeature * When enabled, the parser returns {@link JsonToken#VALUE_EMBEDDED_OBJECT} with * a value of {@code null}, allowing the caller to distinguish {@code undefined} from actual * {@link JsonToken#VALUE_NULL}. - * When disabled {@code undefined} value is reported as {@link JsonToken#VALUE_NULL}. + * When disabled, {@code undefined} value is reported as simple {@link JsonToken#VALUE_NULL}. *

- * The default value is {@code false} for backwards compatibility (with versions prior to 2.20). + * The default value is {@code true} in Jackson 3.x (was {@code false} in Jackson 2.x). */ - READ_UNDEFINED_AS_EMBEDDED_OBJECT(false), + READ_UNDEFINED_AS_EMBEDDED_OBJECT(true), /** * Feature that determines how a CBOR "simple value" of major type 7 is exposed by parser. @@ -46,11 +46,11 @@ public enum CBORReadFeature implements FormatFeature * When enabled, the parser returns {@link JsonToken#VALUE_EMBEDDED_OBJECT} with * an embedded value of type {@link CBORSimpleValue}, allowing the caller to distinguish * these values from actual {@link JsonToken#VALUE_NUMBER_INT}s. - * When disabled, simple values are returned as {@link JsonToken#VALUE_NUMBER_INT}. + * When disabled, simple values are returned as {@link JsonToken#VALUE_NUMBER_INT}s. *

- * The default value is {@code false} for backwards compatibility (with versions prior to 2.20). + * The default value is {@code true} in Jackson 3.x (was {@code false} in Jackson 2.x). */ - READ_SIMPLE_VALUE_AS_EMBEDDED_OBJECT(false) + READ_SIMPLE_VALUE_AS_EMBEDDED_OBJECT(true) ; private final boolean _defaultState; diff --git a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORWriteFeature.java b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORWriteFeature.java index 37ef15838..fd7319973 100644 --- a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORWriteFeature.java +++ b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORWriteFeature.java @@ -68,16 +68,16 @@ public enum CBORWriteFeature implements FormatFeature * or using legacy Jackson encoding logic (encoding up to Jackson 2.19). * When enabled, uses CBOR standard specified encoding of negative values * (e.g., -1 is encoded {@code [0xC3, 0x41, 0x00]}). - * When disabled, maintains backwards compatibility with existing implementations + * When disabled, maintains behavior of versions prior to 3.0. * (e.g., -1 is encoded {@code [0xC3, 0x41, 0x01]}) and uses legacy Jackson encoding. *

* Note that there is the counterpart * {@link CBORReadFeature#DECODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING} * for encoding. *

- * Default value is {@code false} for backwards-compatibility. + * The default value is {@code true} in Jackson 3.x (was {@code false} in Jackson 2.x). */ - ENCODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING(false), + ENCODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING(true), ; diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/CBORFactoryPropertiesTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/CBORFactoryPropertiesTest.java index 2caf31d40..cdcc3d270 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/CBORFactoryPropertiesTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/CBORFactoryPropertiesTest.java @@ -20,6 +20,18 @@ public class CBORFactoryPropertiesTest extends CBORTestBase private final static CBORFactory CBOR_F = new CBORFactory(); + @Test + public void testFactoryDefaults() { + CBORFactory f = new CBORFactory(); + + assertEquals(CBORReadFeature.DECODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING.enabledByDefault(), + f.isEnabled(CBORReadFeature.DECODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING)); + assertEquals(CBORReadFeature.READ_UNDEFINED_AS_EMBEDDED_OBJECT.enabledByDefault(), + f.isEnabled(CBORReadFeature.READ_UNDEFINED_AS_EMBEDDED_OBJECT)); + assertEquals(CBORReadFeature.READ_SIMPLE_VALUE_AS_EMBEDDED_OBJECT.enabledByDefault(), + f.isEnabled(CBORReadFeature.READ_SIMPLE_VALUE_AS_EMBEDDED_OBJECT)); + } + @Test public void testCBORFactorySerializable() throws Exception { @@ -78,7 +90,7 @@ public void testVersions() throws Exception public void testCapabilities() throws Exception { assertTrue(CBOR_F.canHandleBinaryNatively()); - assertEquals(null, CBOR_F.getFormatReadFeatureType()); + assertEquals(CBORReadFeature.class, CBOR_F.getFormatReadFeatureType()); assertEquals(CBORWriteFeature.class, CBOR_F.getFormatWriteFeatureType()); } diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/CBORMapperTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/CBORMapperTest.java index a533edf26..e67073aef 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/CBORMapperTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/CBORMapperTest.java @@ -60,9 +60,7 @@ public void testSimpleNegativeBigInteger() throws Exception { }; // Test correct decoding - CBORMapper mapper1 = CBORMapper.builder() - .enable(CBORReadFeature.DECODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING) - .build(); + CBORMapper mapper1 = CBORMapper.builder().build(); assertEquals(BigInteger.valueOf(-1), mapper1.readValue(encodedNegativeOne, BigInteger.class)); @@ -102,9 +100,7 @@ public void testNegativeBigInteger() throws Exception { }; // Test correct decoding - CBORMapper mapper1 = CBORMapper.builder() - .enable(CBORReadFeature.DECODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING) - .build(); + CBORMapper mapper1 = CBORMapper.builder().build(); assertEquals(new BigInteger("-340282366920938463463374607431768211456"), mapper1.readValue(encodedNegative, BigInteger.class)); @@ -143,9 +139,7 @@ public void testNegativeBigIntegerWithoutLeadingZero() throws Exception { }; // Test correct decoding - CBORMapper mapper1 = CBORMapper.builder() - .enable(CBORReadFeature.DECODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING) - .build(); + CBORMapper mapper1 = CBORMapper.builder().build(); assertEquals(new BigInteger("-340282366920938463463374607431768211456"), mapper1.readValue(encodedNegative, BigInteger.class)); diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/parse/SimpleValuesTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/parse/SimpleValuesTest.java index 143a6c4bf..4aeadda33 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/parse/SimpleValuesTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/parse/SimpleValuesTest.java @@ -17,11 +17,14 @@ public class SimpleValuesTest extends CBORTestBase @Test public void testTinySimpleValues() throws Exception { + CBORFactory f = CBORFactory.builder() + .disable(CBORReadFeature.READ_SIMPLE_VALUE_AS_EMBEDDED_OBJECT) + .build(); // Values 0..19 are unassigned, valid to encounter for (int v = 0; v <= 19; ++v) { byte[] doc = new byte[1]; doc[0] = (byte) (CBORConstants.PREFIX_TYPE_MISC + v); - try (JsonParser p = cborParser(doc)) { + try (JsonParser p = cborParser(f, doc)) { assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken()); // exposes as `int`, fwtw assertEquals(NumberType.INT, p.getNumberType()); @@ -33,14 +36,11 @@ public void testTinySimpleValues() throws Exception @Test public void testTinySimpleValuesAsEmbeddedObjectWhenEnabled() throws Exception { - CBORFactory f = CBORFactory.builder() - .enable(CBORReadFeature.READ_SIMPLE_VALUE_AS_EMBEDDED_OBJECT) - .build(); // Values 0..19 are unassigned, valid to encounter for (int v = 0; v <= 19; ++v) { byte[] doc = new byte[1]; doc[0] = (byte) (CBORConstants.PREFIX_TYPE_MISC + v); - try (CBORParser p = cborParser(f, doc)) { + try (CBORParser p = cborParser(doc)) { assertToken(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken()); assertEquals(new CBORSimpleValue(v), p.getEmbeddedObject()); } @@ -49,10 +49,13 @@ public void testTinySimpleValuesAsEmbeddedObjectWhenEnabled() throws Exception @Test public void testValidByteLengthMinimalValues() throws Exception { + CBORFactory f = CBORFactory.builder() + .disable(CBORReadFeature.READ_SIMPLE_VALUE_AS_EMBEDDED_OBJECT) + .build(); // Values 32..255 are unassigned, valid to encounter for (int v = 32; v <= 255; ++v) { byte[] doc = { (byte) (CBORConstants.PREFIX_TYPE_MISC + 24), (byte) v }; - try (JsonParser p = cborParser(doc)) { + try (JsonParser p = cborParser(f, doc)) { assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken()); // exposes as `int`, fwtw assertEquals(NumberType.INT, p.getNumberType()); @@ -64,12 +67,9 @@ public void testValidByteLengthMinimalValues() throws Exception { @Test public void testValidByteLengthMinimalValuesAsEmbeddedObjectWhenEnabled() throws Exception { // Values 32..255 are unassigned, valid to encounter - CBORFactory f = CBORFactory.builder() - .enable(CBORReadFeature.READ_SIMPLE_VALUE_AS_EMBEDDED_OBJECT) - .build(); for (int v = 32; v <= 255; ++v) { byte[] doc = { (byte) (CBORConstants.PREFIX_TYPE_MISC + 24), (byte) v }; - try (CBORParser p = cborParser(f, doc)) { + try (CBORParser p = cborParser( doc)) { assertToken(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken()); assertEquals(new CBORSimpleValue(v), p.getEmbeddedObject()); } diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/parse/UndefinedValueTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/parse/UndefinedValueTest.java index 5263c2ae9..0cb0ea8b4 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/parse/UndefinedValueTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/parse/UndefinedValueTest.java @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test; -import tools.jackson.core.JsonParser; import tools.jackson.core.JsonToken; import tools.jackson.dataformat.cbor.*; import tools.jackson.dataformat.cbor.CBORGenerator; @@ -19,12 +18,14 @@ public class UndefinedValueTest extends CBORTestBase { private final static byte BYTE_UNDEFINED = (byte) CBORConstants.SIMPLE_VALUE_UNDEFINED; - private final CBORFactory CBOR_F = cborFactory(); + private final CBORFactory CBOR_F = CBORFactory.builder() + .disable(CBORReadFeature.READ_UNDEFINED_AS_EMBEDDED_OBJECT) + .build(); @Test public void testUndefinedLiteralStreaming() throws Exception { - try (CBORParser p = cborParser(new byte[] { BYTE_UNDEFINED })) { + try (CBORParser p = cborParser(CBOR_F, new byte[] { BYTE_UNDEFINED })) { assertEquals(JsonToken.VALUE_NULL, p.nextToken()); assertTrue(p.isUndefined()); assertNull(p.nextToken()); @@ -34,10 +35,7 @@ public void testUndefinedLiteralStreaming() throws Exception // @since 2.20 [jackson-dataformats-binary/137] @Test public void testUndefinedLiteralAsEmbeddedObject() throws Exception { - CBORFactory f = CBORFactory.builder() - .enable(CBORReadFeature.READ_UNDEFINED_AS_EMBEDDED_OBJECT) - .build(); - CBORParser p = cborParser(f, new byte[] { BYTE_UNDEFINED }); + CBORParser p = cborParser(new byte[] { BYTE_UNDEFINED }); assertEquals(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken()); assertTrue(p.isUndefined()); @@ -64,15 +62,11 @@ public void testUndefinedInArray() throws Exception // @since 2.20 [jackson-dataformats-binary/137] @Test public void testUndefinedInArrayAsEmbeddedObject() throws Exception { - CBORFactory f = CBORFactory.builder() - .enable(CBORReadFeature.READ_UNDEFINED_AS_EMBEDDED_OBJECT) - .build(); - ByteArrayOutputStream out = new ByteArrayOutputStream(); out.write(CBORConstants.BYTE_ARRAY_INDEFINITE); out.write(BYTE_UNDEFINED); out.write(CBORConstants.BYTE_BREAK); - CBORParser p = cborParser(f, out.toByteArray()); + CBORParser p = cborParser(out.toByteArray()); assertEquals(JsonToken.START_ARRAY, p.nextToken()); assertEquals(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken()); assertTrue(p.isUndefined()); @@ -110,10 +104,6 @@ public void testUndefinedInObject() throws Exception // @since 2.20 [jackson-dataformats-binary/137] @Test public void testUndefinedInObjectAsEmbeddedObject() throws Exception { - CBORFactory f = CBORFactory.builder() - .enable(CBORReadFeature.READ_UNDEFINED_AS_EMBEDDED_OBJECT) - .build(); - ByteArrayOutputStream out = new ByteArrayOutputStream(); CBORGenerator g = cborGenerator(out); g.writeStartObject(); @@ -126,7 +116,7 @@ public void testUndefinedInObjectAsEmbeddedObject() throws Exception { // assume we use end marker for Object, so doc[doc.length - 2] = BYTE_UNDEFINED; - try (CBORParser p = cborParser(f, doc)) { + try (CBORParser p = cborParser(doc)) { assertEquals(JsonToken.START_OBJECT, p.nextToken()); assertEquals(JsonToken.PROPERTY_NAME, p.nextToken()); assertEquals("bar", p.currentName()); diff --git a/release-notes/CREDITS b/release-notes/CREDITS index f3d0bb0fe..27f14275c 100644 --- a/release-notes/CREDITS +++ b/release-notes/CREDITS @@ -6,3 +6,15 @@ binary data formats module, version 3.x Tatu Saloranta, tatu.saloranta@iki.fi: author +-------------------------------------------------------------------------------- +Credits for individual projects, since 3.0.0 +-------------------------------------------------------------------------------- + +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 + (3.0.0) + diff --git a/release-notes/VERSION b/release-notes/VERSION index be9deeb41..d401b8cfc 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -14,14 +14,16 @@ implementations) === Releases === ------------------------------------------------------------------------ -3.0.0-rc4 (10-May-2025) +3.0.0-rc5 (not yet released) -No changes since rc3 +#582: Change defaults for `CBORReadFeature.DECODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING` + and `CBORWriteFeature.ENCODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING` to `true` (enabled) + (contributed by by Fawzi E) +#591: Change `CBOR` Features defaults for 3.0 + (contributed by by Fawzi E) +3.0.0-rc4 (10-May-2025) 3.0.0-rc3 (13-Apr-2025) - -- Branch rename "master" -> "3.x" [JSTEP-12] - 3.0.0-rc2 (28-Mar-2025) No changes since rc1.