Skip to content

Commit 6ad50a5

Browse files
committed
Merge pull request #2 from mattcross/master
fixes jackson-dataformat-msgpack issue #1
2 parents 29117ed + ed02e59 commit 6ad50a5

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

src/main/java/org/msgpack/jackson/dataformat/msgpack/MessagePackParser.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ public JsonToken nextToken() throws IOException, JsonParseException {
108108
stack.pop();
109109
_currToken = _parsingContext.inObject() ? JsonToken.END_OBJECT : JsonToken.END_ARRAY;
110110
_parsingContext = _parsingContext.getParent();
111+
112+
//If the message unpacker has no more tokens just unwind the stack until it's empty.
113+
if(!messageUnpacker.hasNext()) {
114+
if (!stack.isEmpty() && !stack.getFirst().isEmpty()) {
115+
stack.getFirst().consume();
116+
}
117+
}
111118
return _currToken;
112119
}
113120
}
@@ -116,6 +123,7 @@ public JsonToken nextToken() throws IOException, JsonParseException {
116123
if (!_parsingContext.inObject() && !_parsingContext.inArray()) {
117124
throw new IllegalStateException("Not in Object nor Array");
118125
}
126+
119127
_currToken = _parsingContext.inObject() ? JsonToken.END_OBJECT : JsonToken.END_ARRAY;
120128
_parsingContext = _parsingContext.getParent();
121129
messageUnpacker.close();

src/test/java/org/msgpack/jackson/dataformat/msgpack/MessagePackDataformatForPojoTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ public void testNormal() throws IOException {
2727
assertEquals(normalPojo.suit, Suit.HEART);
2828
}
2929

30+
@Test
31+
public void testNestedList() throws IOException {
32+
byte[] bytes = objectMapper.writeValueAsBytes(nestedListPojo);
33+
NestedListPojo value = objectMapper.readValue(bytes, NestedListPojo.class);
34+
assertEquals(nestedListPojo.s, value.s);
35+
assertTrue(Arrays.equals(nestedListPojo.strs.toArray(), value.strs.toArray()));
36+
}
37+
38+
@Test
39+
public void testNestedListComplex() throws IOException {
40+
byte[] bytes = objectMapper.writeValueAsBytes(nestedListComplexPojo);
41+
NestedListComplexPojo value = objectMapper.readValue(bytes, NestedListComplexPojo.class);
42+
assertEquals(nestedListPojo.s, value.s);
43+
assertEquals(nestedListComplexPojo.foos.get(0).t, value.foos.get(0).t);
44+
}
45+
3046
@Test
3147
public void testUsingCustomConstructor() throws IOException {
3248
UsingCustomConstructorPojo orig = new UsingCustomConstructorPojo("komamitsu", 55);

src/test/java/org/msgpack/jackson/dataformat/msgpack/MessagePackDataformatTestBase.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@
1111
import java.io.ByteArrayOutputStream;
1212
import java.io.IOException;
1313
import java.math.BigInteger;
14+
import java.util.ArrayList;
15+
import java.util.Arrays;
16+
import java.util.List;
1417

1518
public class MessagePackDataformatTestBase {
1619
protected MessagePackFactory factory;
1720
protected ByteArrayOutputStream out;
1821
protected ByteArrayInputStream in;
1922
protected ObjectMapper objectMapper;
2023
protected NormalPojo normalPojo;
24+
protected NestedListPojo nestedListPojo;
25+
protected NestedListComplexPojo nestedListComplexPojo;
26+
protected TinyPojo tinyPojo;
2127

2228
@Before
2329
public void setup() {
@@ -35,6 +41,17 @@ public void setup() {
3541
normalPojo.b = new byte[] {0x01, 0x02, (byte) 0xFE, (byte) 0xFF};
3642
normalPojo.bi = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
3743
normalPojo.suit = Suit.HEART;
44+
45+
nestedListPojo = new NestedListPojo();
46+
nestedListPojo.s = "a string";
47+
nestedListPojo.strs = Arrays.asList(new String[] {"string", "another string", "another string"});
48+
49+
tinyPojo = new TinyPojo();
50+
tinyPojo.t = "t string";
51+
nestedListComplexPojo = new NestedListComplexPojo();
52+
nestedListComplexPojo.s = "a string";
53+
nestedListComplexPojo.foos = new ArrayList<TinyPojo>();
54+
nestedListComplexPojo.foos.add(tinyPojo);
3855
}
3956

4057
@After
@@ -60,6 +77,20 @@ public enum Suit {
6077
SPADE, HEART, DIAMOND, CLUB;
6178
}
6279

80+
public static class NestedListPojo {
81+
public String s;
82+
public List<String> strs;
83+
}
84+
85+
public static class TinyPojo {
86+
public String t;
87+
}
88+
89+
public static class NestedListComplexPojo {
90+
public String s;
91+
public List<TinyPojo> foos;
92+
}
93+
6394
public static class NormalPojo {
6495
String s;
6596
public int i;

0 commit comments

Comments
 (0)