Skip to content

Commit 6ab11a8

Browse files
committed
Fixed #64
1 parent 5325ba0 commit 6ab11a8

File tree

13 files changed

+104
-62
lines changed

13 files changed

+104
-62
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroUntypedDeserializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, Typ
5858
* Method called to map a JSON Object into a Java value.
5959
*/
6060
// Would we just be better off deferring to the Map<Object,Object> deserializer?
61+
@Override
6162
protected Object mapObject(JsonParser p, DeserializationContext ctxt) throws IOException {
6263
Object key1;
6364
JsonToken t = p.getCurrentToken();

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/CustomEncodingWrapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public Schema getSchema() {
5252
}
5353
}
5454

55+
@SuppressWarnings("unchecked")
5556
public T read(Object reuse, Decoder in) throws IOException {
5657
try {
5758
return (T) READ.invoke(encoding, reuse, in);

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/MapReader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ protected Scalar(AvroReadContext parent,
109109
_scalarDecoder = sd;
110110
}
111111

112+
@Override
112113
public long getRemainingElements() {
113114
return _count - _index;
114115
}
@@ -185,6 +186,7 @@ public NonScalar(AvroReadContext parent,
185186
_structureReader = reader;
186187
}
187188

189+
@Override
188190
public long getRemainingElements() {
189191
return _count - _index;
190192
}
@@ -193,6 +195,7 @@ public long getRemainingElements() {
193195
public MapReader newReader(AvroReadContext parent, AvroParserImpl parser) {
194196
return new NonScalar(parent, parser, _structureReader, _typeId, _keyTypeId);
195197
}
198+
196199
@Override
197200
public JsonToken nextToken() throws IOException
198201
{

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/AvroSchemaHelper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public abstract class AvroSchemaHelper
4848
*
4949
* @since 2.8.8
5050
*/
51-
public static final String AVRO_SCHEMA_PROP_ELEMENT_CLASS = SpecificData.ELEMENT_PROP;
51+
public static final String AVRO_SCHEMA_PROP_ELEMENT_CLASS = SpecificData.ELEMENT_PROP;
5252
/**
5353
* Default stringable classes
5454
*
@@ -61,7 +61,8 @@ public abstract class AvroSchemaHelper
6161
));
6262

6363
/**
64-
* Checks if a given type is "Stringable", that is one of the default {@link #STRINGABLE_CLASSES}, is an {@code Enum},
64+
* Checks if a given type is "Stringable", that is one of the default
65+
* {@link #STRINGABLE_CLASSES}, is an {@code Enum},
6566
* or is annotated with
6667
* {@link Stringable @Stringable} and has a constructor that takes a single string argument capable of deserializing the output of its
6768
* {@code toString()} method.
@@ -89,7 +90,7 @@ public static boolean isStringable(AnnotatedClass type) {
8990
protected static String getNamespace(JavaType type) {
9091
Class<?> cls = type.getRawClass();
9192
// 16-Feb-2017, tatu: Fixed as suggested by `baharclerode@github`;
92-
// NOTE: was revert in 2.8.8, but is enabled for Jackson 2.9.
93+
// NOTE: was reverted in 2.8.8, but is enabled for Jackson 2.9.
9394
Class<?> enclosing = cls.getEnclosingClass();
9495
if (enclosing != null) {
9596
return enclosing.getName() + "$";

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/ser/CustomEncodingDatum.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public CustomEncodingDatum(CustomEncodingWrapper<T> encoding, T datum) {
2222
this._datum = datum;
2323
}
2424

25+
@Override
2526
public void write(Encoder encoder) throws IOException {
2627
_encoding.write(_datum, encoder);
2728
}

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,9 +1596,8 @@ public Number getNumberValue() throws IOException
15961596
return _numberBigDecimal;
15971597
}
15981598

1599-
/* And then floating point types. But here optimal type
1600-
* needs to be big decimal, to avoid losing any data?
1601-
*/
1599+
// And then floating point types. But here optimal type
1600+
// needs to be big decimal, to avoid losing any data?
16021601
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
16031602
return _numberBigDecimal;
16041603
}
@@ -1897,14 +1896,6 @@ protected void convertNumberToBigDecimal() throws IOException
18971896
_numTypesValid |= NR_BIGDECIMAL;
18981897
}
18991898

1900-
protected void reportOverflowInt() throws IOException {
1901-
_reportError("Numeric value ("+getText()+") out of range of int ("+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE+")");
1902-
}
1903-
1904-
protected void reportOverflowLong() throws IOException {
1905-
_reportError("Numeric value ("+getText()+") out of range of long ("+Long.MIN_VALUE+" - "+Long.MAX_VALUE+")");
1906-
}
1907-
19081899
/*
19091900
/**********************************************************
19101901
/* Internal methods, secondary parsing

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

Lines changed: 84 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,9 @@ public class ProtobufParser extends ParserMinimalBase
271271

272272
// And then floating point types
273273

274-
final protected static int NR_DOUBLE = 0x008;
275-
final protected static int NR_BIGDECIMAL = 0x0010;
274+
final protected static int NR_FLOAT = 0x008;
275+
final protected static int NR_DOUBLE = 0x010;
276+
final protected static int NR_BIGDECIMAL = 0x0020;
276277

277278
// Also, we need some numeric constants
278279

@@ -298,7 +299,7 @@ public class ProtobufParser extends ParserMinimalBase
298299

299300
final static double MIN_INT_D = (double) Integer.MIN_VALUE;
300301
final static double MAX_INT_D = (double) Integer.MAX_VALUE;
301-
302+
302303
/**
303304
* Bitfield that indicates which numeric representations
304305
* have been calculated for the current type
@@ -308,6 +309,8 @@ public class ProtobufParser extends ParserMinimalBase
308309
// First primitives
309310

310311
protected int _numberInt;
312+
protected float _numberFloat;
313+
311314
protected long _numberLong;
312315
protected double _numberDouble;
313316

@@ -802,8 +805,8 @@ private JsonToken _readNextValue(FieldType t, int nextState) throws IOException
802805
type = JsonToken.VALUE_NUMBER_FLOAT;
803806
break;
804807
case FLOAT:
805-
_numberDouble = (double) Float.intBitsToFloat(_decode32Bits());
806-
_numTypesValid = NR_DOUBLE;
808+
_numberFloat = Float.intBitsToFloat(_decode32Bits());
809+
_numTypesValid = NR_FLOAT;
807810
type = JsonToken.VALUE_NUMBER_FLOAT;
808811
break;
809812
case VINT32_Z:
@@ -1478,7 +1481,23 @@ public int readBinaryValue(Base64Variant b64variant, OutputStream out) throws IO
14781481
/* Numeric accessors of public API
14791482
/**********************************************************
14801483
*/
1481-
1484+
1485+
@Override // since 2.9
1486+
public boolean isNaN() {
1487+
if (_currToken == JsonToken.VALUE_NUMBER_FLOAT) {
1488+
if ((_numTypesValid & NR_DOUBLE) != 0) {
1489+
// 10-Mar-2017, tatu: Alas, `Double.isFinite(d)` only added in JDK 8
1490+
double d = _numberDouble;
1491+
return Double.isNaN(d) || Double.isInfinite(d);
1492+
}
1493+
if ((_numTypesValid & NR_FLOAT) != 0) {
1494+
float f = _numberFloat;
1495+
return Float.isNaN(f) || Float.isInfinite(f);
1496+
}
1497+
}
1498+
return false;
1499+
}
1500+
14821501
@Override
14831502
public Number getNumberValue() throws IOException
14841503
{
@@ -1499,17 +1518,19 @@ public Number getNumberValue() throws IOException
14991518
// Shouldn't get this far but if we do
15001519
return _numberBigDecimal;
15011520
}
1502-
1503-
/* And then floating point types. But here optimal type
1504-
* needs to be big decimal, to avoid losing any data?
1505-
*/
1521+
1522+
// And then floating point types. But here optimal type
1523+
// needs to be big decimal, to avoid losing any data?
15061524
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
15071525
return _numberBigDecimal;
15081526
}
1509-
if ((_numTypesValid & NR_DOUBLE) == 0) { // sanity check
1527+
if ((_numTypesValid & NR_DOUBLE) != 0) {
1528+
return _numberDouble;
1529+
}
1530+
if ((_numTypesValid & NR_FLOAT) == 0) { // sanity check
15101531
_throwInternal();
15111532
}
1512-
return _numberDouble;
1533+
return _numberFloat;
15131534
}
15141535

15151536
@Override
@@ -1537,9 +1558,12 @@ public NumberType getNumberType() throws IOException
15371558
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
15381559
return NumberType.BIG_DECIMAL;
15391560
}
1540-
return NumberType.DOUBLE;
1561+
if ((_numTypesValid & NR_DOUBLE) != 0) {
1562+
return NumberType.DOUBLE;
1563+
}
1564+
return NumberType.FLOAT;
15411565
}
1542-
1566+
15431567
@Override
15441568
public int getIntValue() throws IOException
15451569
{
@@ -1585,16 +1609,21 @@ public BigInteger getBigIntegerValue() throws IOException
15851609
@Override
15861610
public float getFloatValue() throws IOException
15871611
{
1588-
double value = getDoubleValue();
1589-
/* 22-Jan-2009, tatu: Bounds/range checks would be tricky
1590-
* here, so let's not bother even trying...
1591-
*/
1612+
if ((_numTypesValid & NR_FLOAT) == 0) {
1613+
if (_numTypesValid == NR_UNKNOWN) {
1614+
_checkNumericValue(NR_FLOAT);
1615+
}
1616+
if ((_numTypesValid & NR_FLOAT) == 0) {
1617+
convertNumberToFloat();
1618+
}
1619+
}
1620+
// Bounds/range checks would be tricky here, so let's not bother even trying...
15921621
/*
15931622
if (value < -Float.MAX_VALUE || value > MAX_FLOAT_D) {
15941623
_reportError("Numeric value ("+getText()+") out of range of Java float");
15951624
}
15961625
*/
1597-
return (float) value;
1626+
return _numberFloat;
15981627
}
15991628

16001629
@Override
@@ -1640,18 +1669,6 @@ protected void _checkNumericValue(int expType) throws IOException
16401669
_reportError("Current token ("+_currToken+") not numeric, can not use numeric value accessors");
16411670
}
16421671

1643-
@Override // since 2.9
1644-
public boolean isNaN() {
1645-
if (_currToken == JsonToken.VALUE_NUMBER_FLOAT) {
1646-
if ((_numTypesValid & NR_DOUBLE) != 0) {
1647-
// 10-Mar-2017, tatu: Alas, `Double.isFinite(d)` only added in JDK 8
1648-
double d = _numberDouble;
1649-
return Double.isNaN(d) || Double.isInfinite(d);
1650-
}
1651-
}
1652-
return false;
1653-
}
1654-
16551672
protected void convertNumberToInt() throws IOException
16561673
{
16571674
// First, converting from long ought to be easy
@@ -1674,6 +1691,11 @@ protected void convertNumberToInt() throws IOException
16741691
reportOverflowInt();
16751692
}
16761693
_numberInt = (int) _numberDouble;
1694+
} else if ((_numTypesValid & NR_FLOAT) != 0) {
1695+
if (_numberFloat < MIN_INT_D || _numberFloat > MAX_INT_D) {
1696+
reportOverflowInt();
1697+
}
1698+
_numberInt = (int) _numberFloat;
16771699
} else if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
16781700
if (BD_MIN_INT.compareTo(_numberBigDecimal) > 0
16791701
|| BD_MAX_INT.compareTo(_numberBigDecimal) < 0) {
@@ -1697,11 +1719,15 @@ protected void convertNumberToLong() throws IOException
16971719
}
16981720
_numberLong = _numberBigInt.longValue();
16991721
} else if ((_numTypesValid & NR_DOUBLE) != 0) {
1700-
// Need to check boundaries
17011722
if (_numberDouble < MIN_LONG_D || _numberDouble > MAX_LONG_D) {
17021723
reportOverflowLong();
17031724
}
17041725
_numberLong = (long) _numberDouble;
1726+
} else if ((_numTypesValid & NR_FLOAT) != 0) {
1727+
if (_numberFloat < MIN_LONG_D || _numberFloat > MAX_LONG_D) {
1728+
reportOverflowInt();
1729+
}
1730+
_numberLong = (long) _numberFloat;
17051731
} else if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
17061732
if (BD_MIN_LONG.compareTo(_numberBigDecimal) > 0
17071733
|| BD_MAX_LONG.compareTo(_numberBigDecimal) < 0) {
@@ -1725,18 +1751,42 @@ protected void convertNumberToBigInteger() throws IOException
17251751
_numberBigInt = BigInteger.valueOf(_numberInt);
17261752
} else if ((_numTypesValid & NR_DOUBLE) != 0) {
17271753
_numberBigInt = BigDecimal.valueOf(_numberDouble).toBigInteger();
1754+
} else if ((_numTypesValid & NR_FLOAT) != 0) {
1755+
_numberBigInt = BigDecimal.valueOf(_numberFloat).toBigInteger();
17281756
} else {
17291757
_throwInternal();
17301758
}
17311759
_numTypesValid |= NR_BIGINT;
17321760
}
1733-
1761+
1762+
protected void convertNumberToFloat() throws IOException
1763+
{
1764+
// Note: this MUST start with more accurate representations, since we don't know which
1765+
// value is the original one (others get generated when requested)
1766+
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
1767+
_numberFloat = _numberBigDecimal.floatValue();
1768+
} else if ((_numTypesValid & NR_BIGINT) != 0) {
1769+
_numberFloat = _numberBigInt.floatValue();
1770+
} else if ((_numTypesValid & NR_DOUBLE) != 0) {
1771+
_numberFloat = (float) _numberDouble;
1772+
} else if ((_numTypesValid & NR_LONG) != 0) {
1773+
_numberFloat = (float) _numberLong;
1774+
} else if ((_numTypesValid & NR_INT) != 0) {
1775+
_numberFloat = (float) _numberInt;
1776+
} else {
1777+
_throwInternal();
1778+
}
1779+
_numTypesValid |= NR_FLOAT;
1780+
}
1781+
17341782
protected void convertNumberToDouble() throws IOException
17351783
{
17361784
// Note: this MUST start with more accurate representations, since we don't know which
17371785
// value is the original one (others get generated when requested)
17381786
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
17391787
_numberDouble = _numberBigDecimal.doubleValue();
1788+
} else if ((_numTypesValid & NR_FLOAT) != 0) {
1789+
_numberDouble = (double) _numberFloat;
17401790
} else if ((_numTypesValid & NR_BIGINT) != 0) {
17411791
_numberDouble = _numberBigInt.doubleValue();
17421792
} else if ((_numTypesValid & NR_LONG) != 0) {
@@ -1753,7 +1803,7 @@ protected void convertNumberToBigDecimal() throws IOException
17531803
{
17541804
// Note: this MUST start with more accurate representations, since we don't know which
17551805
// value is the original one (others get generated when requested)
1756-
if ((_numTypesValid & NR_DOUBLE) != 0) {
1806+
if ((_numTypesValid & (NR_DOUBLE | NR_FLOAT)) != 0) {
17571807
// Let's parse from String representation, to avoid rounding errors that
17581808
//non-decimal floating operations would incur
17591809
_numberBigDecimal = NumberInput.parseBigDecimal(getText());
@@ -2453,16 +2503,6 @@ protected final static long _long(int i1, int i2)
24532503
/**********************************************************
24542504
*/
24552505

2456-
protected void reportOverflowInt() throws IOException {
2457-
_reportErrorF("Numeric value (%s) out of range of int (%d - %d)",
2458-
getText(), Integer.MIN_VALUE, Integer.MAX_VALUE);
2459-
}
2460-
2461-
protected void reportOverflowLong() throws IOException {
2462-
_reportErrorF("Numeric value (%s) out of range of long (%d - %d)",
2463-
getText(), Long.MIN_VALUE, Long.MAX_VALUE);
2464-
}
2465-
24662506
private void _reportErrorF(String format, Object... args) throws JsonParseException {
24672507
_reportError(String.format(format, args));
24682508
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.fasterxml.jackson.databind.*;
1010
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
1111
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader;
12+
import com.fasterxml.jackson.dataformat.protobuf.testutil.LimitingInputStream;
1213

1314
public class ReadComplexPojoTest extends ProtobufTestBase
1415
{

protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/schemagen/SchemaGenTest.java renamed to protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/schema/SchemaGenTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.dataformat.protobuf.schemagen;
1+
package com.fasterxml.jackson.dataformat.protobuf.schema;
22

33
import static org.junit.Assert.assertArrayEquals;
44

@@ -14,6 +14,7 @@
1414
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufMessage;
1515
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
1616
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader;
17+
import com.fasterxml.jackson.dataformat.protobuf.schemagen.ProtobufSchemaGenerator;
1718

1819
public class SchemaGenTest extends ProtobufTestBase
1920
{

protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/SchemaParsingTest.java renamed to protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/schema/SchemaParsingTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package com.fasterxml.jackson.dataformat.protobuf;
1+
package com.fasterxml.jackson.dataformat.protobuf.schema;
22

33
import java.util.List;
44

5+
import com.fasterxml.jackson.dataformat.protobuf.ProtobufTestBase;
56
import com.fasterxml.jackson.dataformat.protobuf.schema.NativeProtobufSchema;
67
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField;
78
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufMessage;

0 commit comments

Comments
 (0)