Skip to content

Commit

Permalink
Complete binary codec stream read capability defaulting wrt #307
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 16, 2022
1 parent 9958c03 commit 45e8780
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ private Feature(boolean defaultState) {
public int getMask() { return _mask; }
}

// @since 2.14
protected final static JacksonFeatureSet<StreamReadCapability> ION_READ_CAPABILITIES
= DEFAULT_READ_CAPABILITIES.with(StreamReadCapability.EXACT_FLOATS);

/*
/*****************************************************************
/* Basic configuration
Expand Down Expand Up @@ -219,8 +223,7 @@ public boolean hasTextCharacters() {

@Override // since 2.12
public JacksonFeatureSet<StreamReadCapability> getReadCapabilities() {
// Defaults are fine
return DEFAULT_READ_CAPABILITIES;
return ION_READ_CAPABILITIES;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.StreamReadCapability;

import org.junit.Assert;

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

Assert.assertEquals(className, parser.getTypeId());
}

@Test
public void testParserCapabilities() throws Exception {
IonSystem ion = IonSystemBuilder.standard().build();

Integer intValue = Integer.MAX_VALUE;
IonValue ionInt = ion.newInt(intValue);

try (IonParser p = new IonFactory().createParser(ionInt)) {
// 15-Jan-2021, tatu: 2.14 added this setting, not enabled in
// default set
Assert.assertTrue(p.getReadCapabilities().isEnabled(StreamReadCapability.EXACT_FLOATS));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public class ProtobufParser extends ParserMinimalBase
private final static int STATE_CLOSED = 12;

private final static int[] UTF8_UNIT_CODES = ProtobufUtil.sUtf8UnitLengths;


// @since 2.14
protected final static JacksonFeatureSet<StreamReadCapability> PROTOBUF_READ_CAPABILITIES
= DEFAULT_READ_CAPABILITIES.with(StreamReadCapability.EXACT_FLOATS);

/*
/**********************************************************
/* Configuration
Expand Down Expand Up @@ -333,8 +337,7 @@ public void setCodec(ObjectCodec c) {

@Override // since 2.12
public JacksonFeatureSet<StreamReadCapability> getReadCapabilities() {
// Defaults are fine
return DEFAULT_READ_CAPABILITIES;
return PROTOBUF_READ_CAPABILITIES;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.StreamReadCapability;
import com.fasterxml.jackson.databind.ObjectMapper;

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

public void testCBORFactorySerializable() throws Exception
public void testProtoFactorySerializable() throws Exception
{
ProtobufFactory f = new ProtobufFactory();
byte[] doc = _writeDoc(f);
Expand All @@ -33,7 +34,7 @@ public void testCBORFactorySerializable() throws Exception
assertNotNull(f2);
}

public void testCBORFactoryCopy() throws Exception
public void testProtoFactoryCopy() throws Exception
{
ProtobufFactory f2 = PROTO_F.copy();
assertNotNull(f2);
Expand Down Expand Up @@ -98,9 +99,19 @@ public void testInabilityToWriteChars() throws Exception
} catch (UnsupportedOperationException e) {
verifyException(e, "non-byte-based target");
}

}


// @since 2.14
public void testStreamReadCapabilities() throws Exception
{
byte[] doc = _writeDoc(PROTO_F);
try (JsonParser p = MAPPER.createParser(doc)) {
// 15-Jan-2021, tatu: 2.14 added this setting, not enabled in
// default set
assertTrue(p.getReadCapabilities().isEnabled(StreamReadCapability.EXACT_FLOATS));
}
}

/*
/**********************************************************
/* Helper methods
Expand Down

0 comments on commit 45e8780

Please sign in to comment.