Skip to content

Commit 9650869

Browse files
committed
Complete #253
1 parent 0ba88c2 commit 9650869

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ private Feature(boolean defaultState) {
291291
*/
292292
protected int _quad1, _quad2, _quad3;
293293

294+
/**
295+
* Marker flag to indicate that standard symbol handling is used
296+
* (one with symbol table assisted canonicalization. May be disabled
297+
* in which case alternate stream-line, non-canonicalizing handling
298+
* is used: usually due to set of symbols
299+
* (Object property names) is unbounded and will not benefit from
300+
* canonicalization attempts.
301+
*
302+
* @since 2.13
303+
*/
304+
protected final boolean _symbolsCanonical;
305+
294306
/*
295307
/**********************************************************
296308
/* Constants and fields of former 'JsonNumericParserBase'
@@ -355,6 +367,7 @@ public CBORParser(IOContext ctxt, int parserFeatures, int cborFeatures,
355367
_ioContext = ctxt;
356368
_objectCodec = codec;
357369
_symbols = sym;
370+
_symbolsCanonical = sym.isCanonicalizing();
358371

359372
_inputStream = in;
360373
_inputBuffer = inputBuffer;
@@ -1231,12 +1244,16 @@ public String nextFieldName() throws IOException
12311244
if ((_inputEnd - _inputPtr) < lenMarker) {
12321245
_loadToHaveAtLeast(lenMarker);
12331246
}
1234-
name = _findDecodedFromSymbols(lenMarker);
1235-
if (name != null) {
1236-
_inputPtr += lenMarker;
1247+
if (_symbolsCanonical) {
1248+
name = _findDecodedFromSymbols(lenMarker);
1249+
if (name != null) {
1250+
_inputPtr += lenMarker;
1251+
} else {
1252+
name = _decodeContiguousName(lenMarker);
1253+
name = _addDecodedToSymbols(lenMarker, name);
1254+
}
12371255
} else {
12381256
name = _decodeContiguousName(lenMarker);
1239-
name = _addDecodedToSymbols(lenMarker, name);
12401257
}
12411258
}
12421259
} else {
@@ -2614,12 +2631,16 @@ protected final JsonToken _decodePropertyName() throws IOException
26142631
if ((_inputEnd - _inputPtr) < lenMarker) {
26152632
_loadToHaveAtLeast(lenMarker);
26162633
}
2617-
name = _findDecodedFromSymbols(lenMarker);
2618-
if (name != null) {
2619-
_inputPtr += lenMarker;
2634+
if (_symbolsCanonical) {
2635+
name = _findDecodedFromSymbols(lenMarker);
2636+
if (name != null) {
2637+
_inputPtr += lenMarker;
2638+
} else {
2639+
name = _decodeContiguousName(lenMarker);
2640+
name = _addDecodedToSymbols(lenMarker, name);
2641+
}
26202642
} else {
26212643
name = _decodeContiguousName(lenMarker);
2622-
name = _addDecodedToSymbols(lenMarker, name);
26232644
}
26242645
}
26252646
} else {
@@ -2722,15 +2743,18 @@ private final String _decodeLongerName(int len) throws IOException
27222743
}
27232744
_loadToHaveAtLeast(len);
27242745
}
2725-
String name = _findDecodedFromSymbols(len);
2726-
if (name != null) {
2727-
_inputPtr += len;
2728-
return name;
2746+
if (_symbolsCanonical) {
2747+
String name = _findDecodedFromSymbols(len);
2748+
if (name != null) {
2749+
_inputPtr += len;
2750+
return name;
2751+
}
2752+
name = _decodeContiguousName(len);
2753+
return _addDecodedToSymbols(len, name);
27292754
}
2730-
name = _decodeContiguousName(len);
2731-
return _addDecodedToSymbols(len, name);
2755+
return _decodeContiguousName(len);
27322756
}
2733-
2757+
27342758
private final String _decodeChunkedName() throws IOException
27352759
{
27362760
_finishChunkedText();

cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTableTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ public void testSimpleDefault() throws Exception
8484
// Assumption: there is still non-null symbol table, but has "no canonicalization"
8585
public void testNoCanonicalizeWithMapper() throws Exception
8686
{
87-
if (true) {
88-
return;
89-
}
9087
final byte[] doc = cborDoc(a2q("{ 'x':13, 'y':-999}"));
9188
try (JsonParser p = NO_CAN_MAPPER.createParser(doc)) {
9289
Point point = NO_CAN_MAPPER.readValue(p, Point.class);
@@ -98,10 +95,6 @@ public void testNoCanonicalizeWithMapper() throws Exception
9895
// [dataformats-binary#252]: should be able to prevent canonicalization
9996
public void testSimpleNoCanonicalize() throws Exception
10097
{
101-
// !!! TODO: enable
102-
if (true) {
103-
return;
104-
}
10598
final String[] fieldNames = new String[] {
10699
// Ascii, various lengths
107100
"abc", "abcd123", "abcdefghi123940963", "",

release-notes/VERSION-2.x

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ Modules:
1212

1313
2.13.0 (not yet released)
1414

15-
#239: Should validate UTF-8 multi-byte validity for short decode path too
16-
#248: Deprecate `CloseSafeUTF8Writer`, remove use
17-
#252: Make `SmileFactory` support `JsonFactory.Feature.CANONICALIZE_FIELD_NAMES`
15+
#239: (cbor) Should validate UTF-8 multi-byte validity for short decode path too
16+
#248: (ion) Deprecate `CloseSafeUTF8Writer`, remove use
17+
#252: (smile) Make `SmileFactory` support `JsonFactory.Feature.CANONICALIZE_FIELD_NAMES`
18+
#253: (cbor) Make `CBORFactory` support `JsonFactory.Feature.CANONICALIZE_FIELD_NAMES`
1819
- `Ion-java` dep 1.4.0 -> 1.8.0
1920

2021
2.12.2 (03-Mar-2021)

0 commit comments

Comments
 (0)