序列化and反序列化数据从未如此简单(ReflectyIo)

先来看一个 json的sample

       @XmlElement("info")
       public class Info {
             private String addr;
             private String phone;
        }
        Info info = new Info();
        info.setAddr("addr1");
        info.setPhone("12345");

        ReflectyIo io = new ReflectyIo()
                .json()  
                .type(Info.class)
                .build();
        StringWriter writer = new StringWriter();
        io.write(writer, info);  
        System.out.println(writer.toString());        
 //------------  json ouput is:
        {"addr":"addr1","phone":"12345"}
//------------  

再看 一个xml的sample

        ReflectyIo io = new ReflectyIo()
                .xml()  
                .type(Info.class)
                .build();
        StringWriter writer = new StringWriter();
        io.write(writer, info);
        System.out.println(writer.toString());          
 //------------  xml ouput is:
       
//------------  

还不够?再看yaml的sample

        ReflectyIo io = new ReflectyIo()
                .yaml()  
                .type(Info.class)
                .build();
        StringWriter writer = new StringWriter();
        io.write(writer, info);          
        System.out.println(writer.toString());
 //------------  xml ouput is:
    addr: addr1
     phone: 12345
//------------  

如果喜欢这样的框架。请移步[ReflectyIo](https://github.com/LightSun/ReflectyIO

)
如果这些格式都不满足你。 那么请尝试自定义插件吧。ReflectyPlugin

你可能感兴趣的:(序列化and反序列化数据从未如此简单(ReflectyIo))