Skip to content

Commit 3f919e7

Browse files
author
takeshita
committed
Improve implementation and test for nested list.
1 parent 040fbff commit 3f919e7

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/main/java/org/msgpack/template/TemplateRegistry.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ private void registerTemplates() {
134134
/*register(List.class, new ListTemplate(AnyTemplate.getInstance(this)));
135135
register(Collection.class,new CollectionTemplate(AnyTemplate.getInstance(this)));
136136
register(Map.class,new MapTemplate(AnyTemplate.getInstance(this), AnyTemplate.getInstance(this)));
137-
137+
*/
138138
registerGeneric(List.class, new GenericCollectionTemplate(this, ListTemplate.class));
139139
registerGeneric(Collection.class, new GenericCollectionTemplate(this, CollectionTemplate.class));
140-
registerGeneric(Map.class, new GenericMapTemplate(this, MapTemplate.class));*/
140+
registerGeneric(Map.class, new GenericMapTemplate(this, MapTemplate.class));
141141
}
142142

143143

@@ -147,10 +147,10 @@ protected void registerTemplatesWhichRefersRegistry() {
147147
register(List.class, new ListTemplate(anyTemplate));//new ListTemplate(AnyTemplate.getInstance(this)));
148148
register(Collection.class,new CollectionTemplate(anyTemplate));//new CollectionTemplate(AnyTemplate.getInstance(this)));
149149
register(Map.class,new MapTemplate(anyTemplate,anyTemplate));//new MapTemplate(AnyTemplate.getInstance(this), AnyTemplate.getInstance(this)));
150-
150+
/*
151151
registerGeneric(List.class, new GenericCollectionTemplate(this, ListTemplate.class));
152152
registerGeneric(Collection.class, new GenericCollectionTemplate(this, CollectionTemplate.class));
153-
registerGeneric(Map.class, new GenericMapTemplate(this, MapTemplate.class));
153+
registerGeneric(Map.class, new GenericMapTemplate(this, MapTemplate.class));*/
154154
}
155155

156156
public void register(final Class<?> targetClass) {

src/test/java/org/msgpack/TestNestedList.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public void testTestNestedList() throws IOException {
2929
NestedList obj = new NestedList();
3030
obj.list.add(list("aaa", "bbb"));
3131
obj.list.add(list(new MyClass("obj1"), new MyClass("obj2")));
32+
obj.list2.add((List<MyClass>)list(new MyClass("obj3")));
3233

3334
byte[] bytes = messagePack.write(obj);
3435

@@ -37,11 +38,14 @@ public void testTestNestedList() throws IOException {
3738
ArrayValue root = unpacked.asArrayValue().getElementArray()[0].asArrayValue();
3839
ArrayValue list1 = root.getElementArray()[0].asArrayValue();
3940
ArrayValue list2 = root.getElementArray()[1].asArrayValue();
41+
ArrayValue list3 = unpacked.asArrayValue().getElementArray()[1].asArrayValue();
42+
list3 = list3.getElementArray()[0].asArrayValue();
4043

4144
Assert.assertEquals("aaa",list1.getElementArray()[0].asRawValue().getString());
4245
Assert.assertEquals("bbb",list1.getElementArray()[1].asRawValue().getString());
4346
Assert.assertEquals("obj1",messagePack.convert(list2.getElementArray()[0],MyClass.class).name);
4447
Assert.assertEquals("obj2",messagePack.convert(list2.getElementArray()[1],MyClass.class).name);
48+
Assert.assertEquals("obj3",messagePack.convert(list3.getElementArray()[0],MyClass.class).name);
4549

4650
}
4751

@@ -57,6 +61,8 @@ private List<?> list( Object ... elements){
5761
public static class NestedList{
5862
public List<List> list = new ArrayList<List>();
5963

64+
public List<List<MyClass>> list2 = new ArrayList<List<MyClass>>();
65+
6066
}
6167

6268
@Message

0 commit comments

Comments
 (0)