Skip to content

Commit a91c259

Browse files
committed
Fix #31
1 parent d3c4198 commit a91c259

File tree

4 files changed

+115
-4
lines changed

4 files changed

+115
-4
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ private final void _writeNumberNoCheck(long l) throws IOException {
675675
}
676676

677677
private final void _writeNumberNoCheck(double d) throws IOException {
678-
_verifyValueWrite("write number");
679678
_ensureRoomForOutput(11);
680679
// 17-Apr-2010, tatu: could also use 'doubleToIntBits', but it seems
681680
// more accurate to use exact representation; and possibly faster.
@@ -1074,7 +1073,7 @@ protected final void _verifyValueWrite(String typeMsg) throws IOException {
10741073
--count;
10751074

10761075
// 28-Jun-2016, tatu: _Should_ check overrun immediately (instead of waiting
1077-
// for end of Object/Array), but has 10% performane penalty for some reason,
1076+
// for end of Object/Array), but has 10% performance penalty for some reason,
10781077
// should figure out why and how to avoid
10791078
if (count < 0) {
10801079
_failSizedArrayOrObject();
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.fasterxml.jackson.dataformat.cbor.mapper;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.dataformat.cbor.CBORTestBase;
5+
6+
public class NumberBeanTest extends CBORTestBase
7+
{
8+
static class IntsWrapper {
9+
public int[][] values;
10+
11+
protected IntsWrapper() { }
12+
public IntsWrapper(int[][] v) { values = v; }
13+
}
14+
15+
static class LongsWrapper {
16+
public long[][] values;
17+
18+
protected LongsWrapper() { }
19+
public LongsWrapper(long[][] v) { values = v; }
20+
}
21+
22+
static class DoublesWrapper {
23+
public double[][] values;
24+
25+
protected DoublesWrapper() { }
26+
public DoublesWrapper(double[][] v) { values = v; }
27+
}
28+
29+
/*
30+
/**********************************************************
31+
/* Test methods
32+
/**********************************************************
33+
*/
34+
35+
private final ObjectMapper MAPPER = cborMapper();
36+
37+
public void testIntArrayRoundTrip() throws Exception
38+
{
39+
int[][] inputArray = new int[][]{ { -5, 3 } };
40+
byte[] cbor = MAPPER.writeValueAsBytes(new IntsWrapper(inputArray));
41+
IntsWrapper result = MAPPER.readValue(cbor, IntsWrapper.class);
42+
assertNotNull(result);
43+
assertNotNull(result.values);
44+
assertEquals(1, result.values.length);
45+
assertEquals(2, result.values[0].length);
46+
assertEquals(inputArray[0][0], result.values[0][0]);
47+
assertEquals(inputArray[0][1], result.values[0][1]);
48+
}
49+
50+
public void testLongArrayRoundTrip() throws Exception
51+
{
52+
long[][] inputArray = new long[][]{ { 3L + Integer.MAX_VALUE, -3L + Integer.MIN_VALUE } };
53+
byte[] cbor = MAPPER.writeValueAsBytes(new LongsWrapper(inputArray));
54+
LongsWrapper result = MAPPER.readValue(cbor, LongsWrapper.class);
55+
assertNotNull(result);
56+
assertNotNull(result.values);
57+
assertEquals(1, result.values.length);
58+
assertEquals(2, result.values[0].length);
59+
assertEquals(inputArray[0][0], result.values[0][0]);
60+
assertEquals(inputArray[0][1], result.values[0][1]);
61+
}
62+
63+
// for [dataformats-binary#31]
64+
public void testDoubleArrayRoundTrip() throws Exception
65+
{
66+
double[][] inputArray = new double[][]{ { 0.25, -1.5 } };
67+
byte[] cbor = MAPPER.writeValueAsBytes(new DoublesWrapper(inputArray));
68+
DoublesWrapper result = MAPPER.readValue(cbor, DoublesWrapper.class);
69+
assertNotNull(result);
70+
assertNotNull(result.values);
71+
assertEquals(1, result.values.length);
72+
assertEquals(2, result.values[0].length);
73+
assertEquals(inputArray[0][0], result.values[0][0]);
74+
assertEquals(inputArray[0][1], result.values[0][1]);
75+
}
76+
}

release-notes/VERSION

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@ Modules:
99
=== Releases ===
1010
------------------------------------------------------------------------
1111

12+
2.9.0 (not yet released)
13+
14+
2.8.5 (not yet released)
15+
16+
#31 (cbor): Exception serializing double[][]
17+
1218
2.8.4 (14-Oct-2016)
1319

1420
No changes since 2.8.3
1521

1622
2.8.3 (17-Sep-2016)
1723

18-
#28: Java float deserialized as `DoubleNode` instance
24+
#28 (avro): Java float deserialized as `DoubleNode` instance
1925
(reported by teabot@github)
2026

2127
2.8.2 (30-Aug-2016)
2228

23-
#27: (protobuf) Fixed long deserialization problem for longs of ~13digit length
29+
#27 (protobuf): Fixed long deserialization problem for longs of ~13digit length
2430
(contributed by Michael Z)
2531

2632
2.8.1 (20-Jul-2016)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.fasterxml.jackson.dataformat.smile.mapper;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.dataformat.smile.BaseTestForSmile;
5+
6+
public class NumberBeanTest extends BaseTestForSmile
7+
{
8+
static class DoublesWrapper {
9+
public double[][] values;
10+
11+
protected DoublesWrapper() { }
12+
public DoublesWrapper(double[][] v) { values = v; }
13+
}
14+
15+
private final ObjectMapper MAPPER = smileMapper();
16+
17+
// for [dataformats-binary#31]
18+
public void testDoubleArrayRoundTrip() throws Exception
19+
{
20+
double[][] inputArray = new double[][]{ { 0.25, -1.5 } };
21+
byte[] cbor = MAPPER.writeValueAsBytes(new DoublesWrapper(inputArray));
22+
DoublesWrapper result = MAPPER.readValue(cbor, DoublesWrapper.class);
23+
assertNotNull(result);
24+
assertNotNull(result.values);
25+
assertEquals(1, result.values.length);
26+
assertEquals(2, result.values[0].length);
27+
assertEquals(inputArray[0][0], result.values[0][0]);
28+
assertEquals(inputArray[0][1], result.values[0][1]);
29+
}
30+
}

0 commit comments

Comments
 (0)