mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-08 10:49:59 +00:00
java: fixes ListTemplate and MapTemplate
This commit is contained in:
parent
e3bf8a404b
commit
19ff0dd17f
3 changed files with 36 additions and 2 deletions
|
|
@ -34,10 +34,11 @@ public class ListTemplate implements Template {
|
|||
}
|
||||
|
||||
public void pack(Packer pk, Object target) throws IOException {
|
||||
if(target instanceof List) {
|
||||
if(!(target instanceof List)) {
|
||||
throw new MessageTypeException();
|
||||
}
|
||||
List<Object> list = (List<Object>)target;
|
||||
pk.packArray(list.size());
|
||||
for(Object element : list) {
|
||||
elementTemplate.pack(pk, element);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,10 +40,11 @@ public class MapTemplate implements Template {
|
|||
}
|
||||
|
||||
public void pack(Packer pk, Object target) throws IOException {
|
||||
if(target instanceof Map) {
|
||||
if(!(target instanceof Map)) {
|
||||
throw new MessageTypeException();
|
||||
}
|
||||
Map<Object,Object> map = (Map<Object,Object>)target;
|
||||
pk.packMap(map.size());
|
||||
for(Map.Entry<Object,Object> pair : map.entrySet()) {
|
||||
keyTemplate.pack(pk, pair.getKey());
|
||||
valueTemplate.pack(pk, pair.getValue());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue