mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 10:19:51 +00:00
java: adds ReflectionPacker and ReflectionTemplate
This commit is contained in:
parent
7161a235f1
commit
002b86198c
5 changed files with 196 additions and 1 deletions
|
|
@ -0,0 +1,46 @@
|
|||
package org.msgpack;
|
||||
|
||||
import static org.msgpack.Templates.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TestReflectionPackerTemplate {
|
||||
|
||||
public static class StringFieldClass {
|
||||
public String s1;
|
||||
public String s2;
|
||||
public StringFieldClass() { }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackConvert() throws Exception {
|
||||
tString();
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
||||
MessagePacker packer = ReflectionPacker.create(StringFieldClass.class);
|
||||
|
||||
StringFieldClass src = new StringFieldClass();
|
||||
|
||||
src.s1 = "kumofs";
|
||||
src.s2 = "frsyuki";
|
||||
|
||||
packer.pack(new Packer(out), src);
|
||||
|
||||
Template tmpl = ReflectionTemplate.create(StringFieldClass.class);
|
||||
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
|
||||
Object obj = tmpl.unpack(new Unpacker(in));
|
||||
assertEquals(obj.getClass(), StringFieldClass.class);
|
||||
|
||||
StringFieldClass dst = (StringFieldClass)obj;
|
||||
assertEquals(src.s1, dst.s1);
|
||||
assertEquals(src.s2, dst.s2);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue