Skip to content

Commit f9ad899

Browse files
committed
Fix #28
1 parent a824a83 commit f9ad899

File tree

4 files changed

+82
-8
lines changed

4 files changed

+82
-8
lines changed

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/failing/BinaryDataTest.java renamed to avro/src/test/java/com/fasterxml/jackson/dataformat/avro/BinaryDataTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.dataformat.avro.failing;
1+
package com.fasterxml.jackson.dataformat.avro;
22

33
import java.io.IOException;
44

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.fasterxml.jackson.dataformat.cbor.mapper;
2+
3+
import org.junit.Assert;
4+
5+
import com.fasterxml.jackson.databind.JsonNode;
6+
import com.fasterxml.jackson.databind.ObjectMapper;
7+
import com.fasterxml.jackson.databind.node.ObjectNode;
8+
import com.fasterxml.jackson.dataformat.cbor.CBORTestBase;
9+
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
10+
11+
public class TreeNodesTest extends CBORTestBase
12+
{
13+
private final ObjectMapper MAPPER = new ObjectMapper(new CBORFactory());
14+
15+
public void testSimple() throws Exception
16+
{
17+
// create the serialized JSON with byte array
18+
ObjectNode top1 = MAPPER.createObjectNode();
19+
ObjectNode foo1 = top1.putObject("foo");
20+
foo1.put("bar", "baz");
21+
final String TEXT = "Caf\u00e9 1\u20ac";
22+
final byte[] TEXT_BYTES = TEXT.getBytes("UTF-8");
23+
foo1.put("dat", TEXT_BYTES);
24+
25+
byte[] doc = MAPPER.writeValueAsBytes(top1);
26+
// now, deserialize
27+
JsonNode top2 = MAPPER.readValue(doc, JsonNode.class);
28+
JsonNode foo2 = top2.get("foo");
29+
assertEquals("baz", foo2.get("bar").textValue());
30+
31+
JsonNode datNode = foo2.get("dat");
32+
if (!datNode.isBinary()) {
33+
fail("Expected binary node; got "+datNode.getClass().getName());
34+
}
35+
byte[] bytes = datNode.binaryValue();
36+
Assert.assertArrayEquals(TEXT_BYTES, bytes);
37+
}
38+
39+
public void testNumbers() throws Exception
40+
{
41+
ObjectNode root = MAPPER.createObjectNode();
42+
root.put("value", 0.25f);
43+
44+
byte[] doc = MAPPER.writeValueAsBytes(root);
45+
// now, deserialize
46+
JsonNode result = MAPPER.readValue(doc, JsonNode.class);
47+
assertEquals(1, result.size());
48+
49+
// and verify we get FloatNode
50+
JsonNode valueNode = result.get("value");
51+
assertNotNull(valueNode);
52+
assertTrue(valueNode.isNumber());
53+
assertTrue(valueNode.isFloatingPointNumber());
54+
assertTrue(valueNode.isFloat());
55+
}
56+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
<properties>
3535
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
36-
<version.jackson.core>2.8.2</version.jackson.core>
36+
<version.jackson.core>2.8.3-SNAPSHOT</version.jackson.core>
3737
<version.asm>5.1</version.asm>
3838
</properties>
3939

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/mapper/TreeNodesTest.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010

1111
public class TreeNodesTest extends BaseTestForSmile
1212
{
13+
private final ObjectMapper MAPPER = new ObjectMapper(new SmileFactory());
14+
1315
public void testSimple() throws Exception
1416
{
1517
// create the serialized JSON with byte array
16-
ObjectMapper mapper = new ObjectMapper(new SmileFactory());
17-
18-
ObjectNode top1 = mapper.createObjectNode();
18+
ObjectNode top1 = MAPPER.createObjectNode();
1919
ObjectNode foo1 = top1.putObject("foo");
2020
foo1.put("bar", "baz");
2121
final String TEXT = "Caf\u00e9 1\u20ac";
2222
final byte[] TEXT_BYTES = TEXT.getBytes("UTF-8");
2323
foo1.put("dat", TEXT_BYTES);
24-
25-
byte[] doc = mapper.writeValueAsBytes(top1);
24+
25+
byte[] doc = MAPPER.writeValueAsBytes(top1);
2626
// now, deserialize
27-
JsonNode top2 = mapper.readValue(doc, JsonNode.class);
27+
JsonNode top2 = MAPPER.readValue(doc, JsonNode.class);
2828
JsonNode foo2 = top2.get("foo");
2929
assertEquals("baz", foo2.get("bar").textValue());
3030

@@ -35,4 +35,22 @@ public void testSimple() throws Exception
3535
byte[] bytes = datNode.binaryValue();
3636
Assert.assertArrayEquals(TEXT_BYTES, bytes);
3737
}
38+
39+
public void testNumbers() throws Exception
40+
{
41+
ObjectNode root = MAPPER.createObjectNode();
42+
root.put("value", 0.25f);
43+
44+
byte[] doc = MAPPER.writeValueAsBytes(root);
45+
// now, deserialize
46+
JsonNode result = MAPPER.readValue(doc, JsonNode.class);
47+
assertEquals(1, result.size());
48+
49+
// and verify we get FloatNode
50+
JsonNode valueNode = result.get("value");
51+
assertNotNull(valueNode);
52+
assertTrue(valueNode.isNumber());
53+
assertTrue(valueNode.isFloatingPointNumber());
54+
assertTrue(valueNode.isFloat());
55+
}
3856
}

0 commit comments

Comments
 (0)