Skip to content

Commit 1dad25b

Browse files
committed
Merge branch '2.x' into 3.x
2 parents e330141 + 7736252 commit 1dad25b

File tree

4 files changed

+26
-42
lines changed

4 files changed

+26
-42
lines changed

cbor/src/main/java/tools/jackson/dataformat/cbor/CBORParser.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public int getFirstTag() {
130130
/* Configuration
131131
/**********************************************************************
132132
*/
133-
133+
134134
/**
135135
* Bit flag composed of bits that indicate which
136136
* {@link CBORReadFeature}s are enabled.
@@ -1963,15 +1963,13 @@ private final byte[] _getBinaryFromString(Base64Variant variant) throws JacksonE
19631963
}
19641964

19651965
/**
1966-
* Checking whether the current token represents an `undefined` value (0xF7).
1966+
* Checking whether the current token represents an {@code undefined} value ({@code 0xF7}).
19671967
* <p>
1968-
* This method allows distinguishing between real {@code null} and `undefined`,
1969-
* even if {@link CBORReadFeature#HANDLE_UNDEFINED_AS_EMBEDDED_OBJECT} is disabled
1968+
* This method allows distinguishing between real {@code null} and {@code undefined},
1969+
* even if {@link CBORReadFeature#READ_UNDEFINED_AS_EMBEDDED_OBJECT} is disabled
19701970
* and the token is reported as {@link JsonToken#VALUE_NULL}.
19711971
*
1972-
* @return {@code true} if current token is an `undefined`, {@code false} otherwise
1973-
*
1974-
* @since 2.20
1972+
* @return {@code true} if current token is an {@code undefined}, {@code false} otherwise
19751973
*/
19761974
public boolean isUndefined() {
19771975
if ((_currToken == JsonToken.VALUE_NULL) || (_currToken == JsonToken.VALUE_EMBEDDED_OBJECT)) {
@@ -3679,19 +3677,9 @@ private final static long _long(int i1, int i2)
36793677
* Helper method to encapsulate details of handling of mysterious `undefined` value
36803678
* that is allowed to be used as something encoder could not handle (as per spec),
36813679
* whatever the heck that should be.
3682-
* <p>
3683-
* For backward compatibility with Jackson 2.10 to 2.19, this value is decoded
3684-
* as {@link JsonToken#VALUE_NULL} by default.
3685-
* <p>
3686-
*
3687-
* since 2.20 If {@link CBORReadFeature#HANDLE_UNDEFINED_AS_EMBEDDED_OBJECT} is enabled,
3688-
* the value will instead be decoded as {@link JsonToken#VALUE_EMBEDDED_OBJECT}
3689-
* with an embedded value of {@code null}.
3690-
*
3691-
* @since 2.10
36923680
*/
36933681
protected JsonToken _decodeUndefinedValue() {
3694-
if (CBORReadFeature.HANDLE_UNDEFINED_AS_EMBEDDED_OBJECT.enabledIn(_formatFeatures)) {
3682+
if (CBORReadFeature.READ_UNDEFINED_AS_EMBEDDED_OBJECT.enabledIn(_formatFeatures)) {
36953683
_binaryValue = null; // should be clear but just in case
36963684
return JsonToken.VALUE_EMBEDDED_OBJECT;
36973685
}
@@ -3705,8 +3693,6 @@ protected JsonToken _decodeUndefinedValue() {
37053693
* As of Jackson 2.12, simple values are exposed as
37063694
* {@link JsonToken#VALUE_NUMBER_INT}s,
37073695
* but in later versions this is planned to be changed to separate value type.
3708-
*
3709-
* @since 2.12
37103696
*/
37113697
public JsonToken _decodeSimpleValue(int lowBits, int ch) throws JacksonException {
37123698
if (lowBits > 24) {

cbor/src/main/java/tools/jackson/dataformat/cbor/CBORReadFeature.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,17 @@ public enum CBORReadFeature implements FormatFeature
2828
DECODE_USING_STANDARD_NEGATIVE_BIGINT_ENCODING(false),
2929

3030
/**
31-
* Feature that determines how an ` undefined ` value (0xF7) is decoded.
31+
* Feature that determines how an {@code undefined} value ({@code 0xF7}) is exposed
32+
* by parser.
3233
* <p>
33-
* When enabled, the parser returns {@link JsonToken#VALUE_EMBEDDED_OBJECT} with a
34-
* value of {@code null}, allowing the caller to distinguish `undefined` from actual
34+
* When enabled, the parser returns {@link JsonToken#VALUE_EMBEDDED_OBJECT} with
35+
* a value of {@code null}, allowing the caller to distinguish {@code undefined} from actual
3536
* {@link JsonToken#VALUE_NULL}.
37+
* When disabled {@code undefined} value is reported as {@link JsonToken#VALUE_NULL}.
3638
*<p>
37-
* When disabled (default, for backwards compatibility), `undefined` value is
38-
* reported as {@link JsonToken#VALUE_NULL}, maintaining legacy behavior from Jackson 2.10 to 2.19.
39-
*
40-
* @since 2.20
39+
* The default value is {@code false} for backwards compatibility (with versions prior to 2.20).
4140
*/
42-
HANDLE_UNDEFINED_AS_EMBEDDED_OBJECT(false)
41+
READ_UNDEFINED_AS_EMBEDDED_OBJECT(false)
4342
;
4443

4544
private final boolean _defaultState;

cbor/src/test/java/tools/jackson/dataformat/cbor/parse/UndefinedValueTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void testUndefinedLiteralStreaming() throws Exception
3535
@Test
3636
public void testUndefinedLiteralAsEmbeddedObject() throws Exception {
3737
CBORFactory f = CBORFactory.builder()
38-
.enable(CBORReadFeature.HANDLE_UNDEFINED_AS_EMBEDDED_OBJECT)
38+
.enable(CBORReadFeature.READ_UNDEFINED_AS_EMBEDDED_OBJECT)
3939
.build();
4040
CBORParser p = cborParser(f, new byte[] { BYTE_UNDEFINED });
4141

@@ -65,7 +65,7 @@ public void testUndefinedInArray() throws Exception
6565
@Test
6666
public void testUndefinedInArrayAsEmbeddedObject() throws Exception {
6767
CBORFactory f = CBORFactory.builder()
68-
.enable(CBORReadFeature.HANDLE_UNDEFINED_AS_EMBEDDED_OBJECT)
68+
.enable(CBORReadFeature.READ_UNDEFINED_AS_EMBEDDED_OBJECT)
6969
.build();
7070

7171
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -111,7 +111,7 @@ public void testUndefinedInObject() throws Exception
111111
@Test
112112
public void testUndefinedInObjectAsEmbeddedObject() throws Exception {
113113
CBORFactory f = CBORFactory.builder()
114-
.enable(CBORReadFeature.HANDLE_UNDEFINED_AS_EMBEDDED_OBJECT)
114+
.enable(CBORReadFeature.READ_UNDEFINED_AS_EMBEDDED_OBJECT)
115115
.build();
116116

117117
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -126,14 +126,14 @@ public void testUndefinedInObjectAsEmbeddedObject() throws Exception {
126126
// assume we use end marker for Object, so
127127
doc[doc.length - 2] = BYTE_UNDEFINED;
128128

129-
CBORParser p = cborParser(f, doc);
130-
assertEquals(JsonToken.START_OBJECT, p.nextToken());
131-
assertEquals(JsonToken.PROPERTY_NAME, p.nextToken());
132-
assertEquals("bar", p.currentName());
133-
assertEquals(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken());
134-
assertTrue(p.isUndefined());
135-
assertEquals(JsonToken.END_OBJECT, p.nextToken());
136-
assertNull(p.nextToken());
137-
p.close();
129+
try (CBORParser p = cborParser(f, doc)) {
130+
assertEquals(JsonToken.START_OBJECT, p.nextToken());
131+
assertEquals(JsonToken.PROPERTY_NAME, p.nextToken());
132+
assertEquals("bar", p.currentName());
133+
assertEquals(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken());
134+
assertTrue(p.isUndefined());
135+
assertEquals(JsonToken.END_OBJECT, p.nextToken());
136+
assertNull(p.nextToken());
137+
}
138138
}
139139
}

release-notes/VERSION-2.x

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ Active maintainers:
1818

1919
#137: (cbor) Allow exposing CBOR "undefined" value as `JsonToken.VALUE_EMBEDDED_OBJECT`;
2020
with embedded value of `null`
21-
(implementation contributed by Fawzi E)
22-
21+
(implementation contributed by Fawzi E)
2322
#431: (cbor) Negative `BigInteger` values not encoded/decoded correctly
2423
(reported by Brian G)
2524
(fix contributed by Fawzi E)

0 commit comments

Comments
 (0)