Skip to content

Commit 45e8780

Browse files
committed
Complete binary codec stream read capability defaulting wrt #307
1 parent 9958c03 commit 45e8780

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ private Feature(boolean defaultState) {
8585
public int getMask() { return _mask; }
8686
}
8787

88+
// @since 2.14
89+
protected final static JacksonFeatureSet<StreamReadCapability> ION_READ_CAPABILITIES
90+
= DEFAULT_READ_CAPABILITIES.with(StreamReadCapability.EXACT_FLOATS);
91+
8892
/*
8993
/*****************************************************************
9094
/* Basic configuration
@@ -219,8 +223,7 @@ public boolean hasTextCharacters() {
219223

220224
@Override // since 2.12
221225
public JacksonFeatureSet<StreamReadCapability> getReadCapabilities() {
222-
// Defaults are fine
223-
return DEFAULT_READ_CAPABILITIES;
226+
return ION_READ_CAPABILITIES;
224227
}
225228

226229
/*

ion/src/test/java/com/fasterxml/jackson/dataformat/ion/IonParserTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.fasterxml.jackson.core.JsonParser;
1818
import com.fasterxml.jackson.core.JsonToken;
19+
import com.fasterxml.jackson.core.StreamReadCapability;
1920

2021
import org.junit.Assert;
2122

@@ -109,4 +110,19 @@ public void testGetTypeId() throws IOException {
109110

110111
Assert.assertEquals(className, parser.getTypeId());
111112
}
113+
114+
@Test
115+
public void testParserCapabilities() throws Exception {
116+
IonSystem ion = IonSystemBuilder.standard().build();
117+
118+
Integer intValue = Integer.MAX_VALUE;
119+
IonValue ionInt = ion.newInt(intValue);
120+
121+
try (IonParser p = new IonFactory().createParser(ionInt)) {
122+
// 15-Jan-2021, tatu: 2.14 added this setting, not enabled in
123+
// default set
124+
Assert.assertTrue(p.getReadCapabilities().isEnabled(StreamReadCapability.EXACT_FLOATS));
125+
}
126+
}
127+
112128
}

protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufParser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public class ProtobufParser extends ParserMinimalBase
5555
private final static int STATE_CLOSED = 12;
5656

5757
private final static int[] UTF8_UNIT_CODES = ProtobufUtil.sUtf8UnitLengths;
58-
58+
59+
// @since 2.14
60+
protected final static JacksonFeatureSet<StreamReadCapability> PROTOBUF_READ_CAPABILITIES
61+
= DEFAULT_READ_CAPABILITIES.with(StreamReadCapability.EXACT_FLOATS);
62+
5963
/*
6064
/**********************************************************
6165
/* Configuration
@@ -333,8 +337,7 @@ public void setCodec(ObjectCodec c) {
333337

334338
@Override // since 2.12
335339
public JacksonFeatureSet<StreamReadCapability> getReadCapabilities() {
336-
// Defaults are fine
337-
return DEFAULT_READ_CAPABILITIES;
340+
return PROTOBUF_READ_CAPABILITIES;
338341
}
339342

340343
/*

protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/FactoryPropertiesTest.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.fasterxml.jackson.core.JsonGenerator;
66
import com.fasterxml.jackson.core.JsonParser;
7+
import com.fasterxml.jackson.core.StreamReadCapability;
78
import com.fasterxml.jackson.databind.ObjectMapper;
89

910
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
@@ -21,7 +22,7 @@ public FactoryPropertiesTest() throws IOException {
2122
POINT_SCHEMA = ProtobufSchemaLoader.std.parse(PROTOC_BOX, "Point");
2223
}
2324

24-
public void testCBORFactorySerializable() throws Exception
25+
public void testProtoFactorySerializable() throws Exception
2526
{
2627
ProtobufFactory f = new ProtobufFactory();
2728
byte[] doc = _writeDoc(f);
@@ -33,7 +34,7 @@ public void testCBORFactorySerializable() throws Exception
3334
assertNotNull(f2);
3435
}
3536

36-
public void testCBORFactoryCopy() throws Exception
37+
public void testProtoFactoryCopy() throws Exception
3738
{
3839
ProtobufFactory f2 = PROTO_F.copy();
3940
assertNotNull(f2);
@@ -98,9 +99,19 @@ public void testInabilityToWriteChars() throws Exception
9899
} catch (UnsupportedOperationException e) {
99100
verifyException(e, "non-byte-based target");
100101
}
101-
102102
}
103-
103+
104+
// @since 2.14
105+
public void testStreamReadCapabilities() throws Exception
106+
{
107+
byte[] doc = _writeDoc(PROTO_F);
108+
try (JsonParser p = MAPPER.createParser(doc)) {
109+
// 15-Jan-2021, tatu: 2.14 added this setting, not enabled in
110+
// default set
111+
assertTrue(p.getReadCapabilities().isEnabled(StreamReadCapability.EXACT_FLOATS));
112+
}
113+
}
114+
104115
/*
105116
/**********************************************************
106117
/* Helper methods

0 commit comments

Comments
 (0)