xstream

序列化框架的选型和比对

流过昼夜 提交于 2019-11-27 20:42:51
序列化通信 将对象转换为字节数组,方便在网络中进行对象的传输。在网络通信中,不同的计算机进行相互通信主要的方式就是将数据流从一台机器传输给另外一台计算机,常见的传输协议包括了TCP,UDP,HTTP等,网络io的方式主要包括有了aio,bio,nio三种方式。 当客户端将需要请求的数据封装好了之后就需要进行转换为 二进制格式 再转换为流进行传输,当服务端接收到流之后再将数据解析为 二进制格式 的内容,再按照约定好的协议进行处理解析。最常见的场景就是rpc远程调用的时候,对发送数据和接收数据时候的处理。 下边我们来一一介绍一下现在比较常见的几款序列化技术框架。 jdk序列化 jdk自身便带有序列化的功能,Java序列化API允许我们将一个对象转换为流,并通过网络发送,或将其存入文件或数据库以便未来使用,反序列化则是将对象流转换为实际程序中使用的Java对象的过程。 先来看看实际的代码案例 首先我们创建一个基础的测试Person类 package com.sise.test; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; /** * @author linhao * @date 2019/8/15 *

threaded_execution参数开启的情况下导致ogg无法注册

夙愿已清 提交于 2019-11-27 20:40:43
GGSCI (localhost.localdomain as c##goldengate@ora12c/CDB$ROOT) 59> dblogin userid c##goldengate, password goldengate Successfully logged into database CDB$ROOT. GGSCI (localhost.localdomain as c##goldengate@ora12c/CDB$ROOT) 60> register extract ext database container (ora12cpdb1) 2019-08-19 09:45:00 ERROR OGG-08221 Cannot register or unregister EXTRACT EXT because of the following SQL error: OCI Error ORA (status = 1031-ORA-01031: insufficient privileges ORA-06512: at "SYS.DBMS_XSTREAM_GG_INTERNAL", line 319 ORA-06512: at "SYS.DBMS_XSTREAM_GG", line 104 ORA-06512: at "SYS.DBMS_XSTREAM_GG",

27AJAX的学习

时光毁灭记忆、已成空白 提交于 2019-11-27 15:24:00
#1 ajax第一个例子、xml方式传递数据 ajax.html&AjaxServlet // 1. 创建XMLHttpRequest对象 为了兼容浏览器,这里需要自己创建一个工厂方法 var xhr = new XMLHttpRequest(); // 此版本暂时没有考虑兼容浏览器的问题 // 2. xhr对象的open方法访问对应的servlet或者文件 xhr.open(“GET”, “ajaxServlet”, true); // todo // 3. 检测xhr对象状态,在合适的时候进行处理 xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { document.getElementById(“data”).innerHTML = xhr.responseText; // 获取字符串的方式 } }; // 4. 发送请求 xhr.send(); // get请求不需要增加参数 // 兼容ie低版本浏览器 function createXMLHttpRequest() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if (window.ActiveXObject) {

How do I encode UTF-8 using the XStream framework?

老子叫甜甜 提交于 2019-11-27 11:20:02
问题 Per XStream's FAQ its default parser does not preserve UTF-8 document encoding, and one must provide their own encoder. How does one do this? Thanks! 回答1: Create a Writer with UTF-8 encoding. Pass the Writer as an argument to XStream's toXML method. XStream xstream = new xStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(outputStream, "UTF-8"); xStream.toXML(object, writer); String xml = outputStream.toString("UTF-8"); You may

xstream CannotResolveClassException

跟風遠走 提交于 2019-11-27 07:37:46
问题 I'm trying to use xstream 1.4.2 to convert xml to object. It does work perfectly fine for me until I put the object's class file in a separate package than where the main code runs. Then I get a CannotResolveClassException. I've tried using the setClassLoader method as recommended by others but that doesn't help. Exception in thread "main" com.thoughtworks.xstream.mapper.CannotResolveClassException: result at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:56) at

How to convert List of Object to XML doc using XStream

二次信任 提交于 2019-11-27 02:19:28
问题 How to convert List of Object to XML doc using XStream ? and how to deserialize it back ? This is my xml <?xml version="1.0" encoding="UTF-8"?> <persons> <person> <fullname>Guilherme</fullname> <age>10</age> <address>address,address,address,address,</address> </person> <person> <fullname>Guilherme</fullname> <age>10</age> <address>address,address,address,address,</address> </person> </persons> Person bean contains 3 fields how to convert back it to Bean List using custom converters ? 回答1: You

XStream : node with attributes and text node?

孤人 提交于 2019-11-27 01:56:20
问题 I would like to serialize an object to an XML of this form with XStream. <node att="value">text</node> The value of the node ( text ) is a field on the serialized object, as well as the att attribute. Is this possible without writing a converter for this object? Thanks! 回答1: write a convertor, it should be something similar to the code snippet class FieldDtoConvertor implements Converter { @SuppressWarnings("unchecked") public boolean canConvert(final Class clazz) { return clazz.equals

Modern alternative to Java XStream library?

一个人想着一个人 提交于 2019-11-27 01:42:50
问题 I used XStream many years ago, but I see that the libraries is not updated since 2008 (latest news). Is there now a more modern and up to dates Java XML serialization library? 回答1: In order of preference, relevancy and activity: JAXB Visit the JAXB project's site to check out the tutorial and guide. Have also a look at the original JAXB architecture whitepaper. The JAXB projet listed above is the reference implementation of the API, and is packaged in by the GlassFish Application Server.

Format XML generated by Xstream

核能气质少年 提交于 2019-11-26 22:04:37
问题 I want to format the output XML generated by Xstream, to make it more readable. Currently, a newline is added after each element but I would like newline to be added after every attribute. Is there a way to do this? Pretty Print Writer is used by default to format the output of the xml but this doesn't suffice for me. I want newline to be added after every 回答1: XStream includes a PrettyPrintWriter After building your XStream... XStream xstream = //...whatever Instead of: // p is my object