Skip to content

Commit 11df915

Browse files
author
takeshita
committed
Add test that convert nested mixed type list to org.msgpack.type.Value.
Change TemplateRegistry@genericCache not to share.
1 parent 11601d4 commit 11df915

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public TemplateRegistry(TemplateRegistry registry) {
8888
}
8989
chain = createTemplateBuilderChain();
9090
cache = new HashMap<Type, Template<Type>>();
91-
genericCache = parent.genericCache;
91+
//genericCache = parent.genericCache;
92+
genericCache = new HashMap<Type, GenericTemplate>();
9293
registerTemplatesWhichRefersRegistry();
9394
}
9495

@@ -130,14 +131,9 @@ private void registerTemplates() {
130131
register(byte[].class, ByteArrayTemplate.getInstance());
131132
register(ByteBuffer.class, ByteBufferTemplate.getInstance());
132133
register(Value.class, ValueTemplate.getInstance());
134+
133135
registerTemplatesWhichRefersRegistry();
134-
/*register(List.class, new ListTemplate(AnyTemplate.getInstance(this)));
135-
register(Collection.class,new CollectionTemplate(AnyTemplate.getInstance(this)));
136-
register(Map.class,new MapTemplate(AnyTemplate.getInstance(this), AnyTemplate.getInstance(this)));
137-
*/
138-
registerGeneric(List.class, new GenericCollectionTemplate(this, ListTemplate.class));
139-
registerGeneric(Collection.class, new GenericCollectionTemplate(this, CollectionTemplate.class));
140-
registerGeneric(Map.class, new GenericMapTemplate(this, MapTemplate.class));
136+
141137
}
142138

143139

@@ -147,10 +143,10 @@ protected void registerTemplatesWhichRefersRegistry() {
147143
register(List.class, new ListTemplate(anyTemplate));//new ListTemplate(AnyTemplate.getInstance(this)));
148144
register(Collection.class,new CollectionTemplate(anyTemplate));//new CollectionTemplate(AnyTemplate.getInstance(this)));
149145
register(Map.class,new MapTemplate(anyTemplate,anyTemplate));//new MapTemplate(AnyTemplate.getInstance(this), AnyTemplate.getInstance(this)));
150-
/*
146+
151147
registerGeneric(List.class, new GenericCollectionTemplate(this, ListTemplate.class));
152148
registerGeneric(Collection.class, new GenericCollectionTemplate(this, CollectionTemplate.class));
153-
registerGeneric(Map.class, new GenericMapTemplate(this, MapTemplate.class));*/
149+
registerGeneric(Map.class, new GenericMapTemplate(this, MapTemplate.class));
154150
}
155151

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

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ public void testTestNestedList() throws IOException {
4949

5050
}
5151

52+
@Test
53+
public void testNestedListToValue() throws IOException {
54+
55+
List values = list( list("hoge",4) , list(list(2,"aaa"),list("bbb")));
56+
57+
Value value = messagePack.unconvert(values);
58+
59+
Value[] rootArray = value.asArrayValue().getElementArray();
60+
Value[] list1 = rootArray[0].asArrayValue().getElementArray();
61+
Value[] list2 = rootArray[1].asArrayValue().getElementArray();
62+
Value[] list3 = list2[0].asArrayValue().getElementArray();
63+
Value[] list4 = list2[1].asArrayValue().getElementArray();
64+
Assert.assertEquals("hoge",list1[0].asRawValue().getString());
65+
Assert.assertEquals(4,list1[1].asIntegerValue().getInt());
66+
Assert.assertEquals(2,list3[0].asIntegerValue().getInt());
67+
Assert.assertEquals("aaa",list3[1].asRawValue().getString());
68+
Assert.assertEquals("bbb",list4[0].asRawValue().getString());
69+
70+
}
71+
5272
private List<?> list( Object ... elements){
5373
List<Object> list = new ArrayList();
5474
for(Object o : elements){

0 commit comments

Comments
 (0)