美文网首页
序列化and反序列化数据从未如此简单(ReflectyIo)

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

作者: LightSun | 来源:发表于2019-05-23 10:15 被阅读0次

    先来看一个 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:
           <info addr="addr1" phone="12345"/>
    //------------  
    

    还不够?再看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)

          本文链接:https://www.haomeiwen.com/subject/eigmzqtx.html