xstream

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

匿名 (未验证) 提交于 2019-12-03 00:56: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 also use that Writer to include the XML Declaration

记一次xstream引起的内存泄漏

匿名 (未验证) 提交于 2019-12-03 00:42:01
一、起 支付系统突然出现频繁的超时,查看error日志没有什么发现,凭经验去gc日志瞅一眼,有频繁的full gc,而且每两次gc,老年代会有80%的内存无法被回收,基本确认是系统出现内存泄漏,导致老年代空间被占满,频繁触发full gc,full gc 触发stop the word,导致业务接口超时。 二、承 2.1、dump内存数据 #netstat -tunlp|grep 端口号 #jmap -dump:live,file=dump.file pid 2.2、解析内存数据 #jhat -J-Xmx8192M dump.file 2.3、分析内存数据 查看实例个数前五的对象,可以看出第一名是第二名的实例个数的十几倍,大概率是class com.thoughtworks.xstream.core.util.CompositeClassLoader 对象造成的内存泄漏。 晚上搜资料,果然是。 我们支付系统在和微信第三方支付系统进行交互处理支付业务时,需要解析微信接口返回的XML数据,用到了xstream,而且每个请求都会新建一个xstream对象,xstream对象内部又会new CompositeClassLoader对象,Class.forName调用该Application ClassLoader,gc时xstream会被回收

Issue with serializing Hibernate objects using XStream

a 夏天 提交于 2019-12-03 00:38:21
I've been facing this issue where, the hibernate objects on serialization produces unexpect xmls containing all the instrumented code from Hibernate. We did some cleaning of the object before serializing the object. But, is there a standard option available to serialize the object directly? Dan Vinton I've not used XStream before, but I have serialized Hibernate-managed entities. It isn't fun. There are two big issues: Lazy loading; One-to-many relationships. The former is obvious - you need the actual data to serialize. The latter is less so - any one-to-many relationships you declare against

大型分布式网站架构设计--第1章 面向服务体系的架构

匿名 (未验证) 提交于 2019-12-03 00:27:02
本章目录: 分布式Java应用图: 分布式Java应用:大型系统会被拆分成多个子系统来实现,对于Java来说,这些子系统可能部署在同一台机器上不同的JVM,或者部署在不同机器上,但是这些子系统之间要进行相互通信来共同实现业务功能。 分布式应用架构的演变 分布式应用架构面临的首要问题,便是如何实现应用之间的远程调用(RPC)。有两种方式:一种是基于HTTP的RPC,一种是基于TCP的RPC。 RPC也就是远程调用,RPC的实现包括客户端和服务端,也就是服务提供方和服务调用方,服务调用方发送RPC请求到服务提供方,服务提供方根据服务调用方的参数执行请求方法,将执行结果返回给调用方,这就是一次RPC请求。 要注意 无论是什么类型的数据,最终都是要转成二进制在网络上传输。 对象的序列化:就是将对象转成二进制流的过程。 对象的反序列化:就是将二进制流转成对象的过程。 Java中的序列化代码: //定义一个字节数组的输出流 ByteArrayOutputStream os= new ByteArrayOutputStream(); //对象的输出流 ObjectOutputStream out = new ObjectOutputStream(os); //将对象写入字节数组输出,进行序列化 out .writeObject(zhangsan); byte [] zhangsanByte=os

Spring O/X 映射

匿名 (未验证) 提交于 2019-12-03 00:22:01
Spring 本身没有提供对象与xml互转的功能,但是它提供了通用的接口来封装各类提供对象与xml互转功能的框架,如:JAXB,Castor,JiBX,XStream。 请参考《 XStream 精萃 》了解如何使用XStream以及如何与 Spring 整合。 Spring Framework 精萃 文章来源: Spring O/X 映射

getting error in xslt transformation through java

别说谁变了你拦得住时间么 提交于 2019-12-02 23:22:37
问题 I am trying to an xsl transformation that right now by a java object I am generating an intermediary XML and that XML is again passed to generate a new XML finally right now while in xsl transformation I am getting the error, let me show you below my piece of code that I have tried. Below is my class in which first I am creating objects and then through xstream generating the intermediary XML InvoiceReferenceNotificationMessage invoiceReferenceNotificationMessage = new

Converting XML into Java Map<String, Integer>

偶尔善良 提交于 2019-12-02 21:59:31
问题 I'm trying to convert XML into Java code. This XML is in a different file; it matches words with numbers (a probability distribution) and looks like this: <?xml version="1.0" encoding="UTF-8" ?> <root> <Durapipe type="int">1</Durapipe> <EXPLAIN type="int">2</EXPLAIN> <woods type="int">2</woods> <hanging type="int">3</hanging> <hastily type="int">2</hastily> <localized type="int">1</localized> <Schuster type="int">5</Schuster> <regularize type="int">1</regularize> <LASR type="int">1</LASR>

XStream and underscores

孤街醉人 提交于 2019-12-02 20:30:28
It looks like XStream (com.thoughtworks.xstream -> xstream 1.4.2) is handling underscores in element and attribute names in a very strange way. I need to fetch and parse an xml from a customer that are having underscores in their attributes. This is my first try with XStream and I'm a bit disappointed as I was hoping to avoid all the ugly xml parsing. Here I provide a small test sample to hi light the behaviour. The last example shows my problem. public class MyTest { public void testIt() { C1 a = new C1(); a.a_b= "a_b"; XStream xstream = new XStream(); xstream.processAnnotations(C1.class);

XStream : node with attributes and text node in xstream 1.3.1?

回眸只為那壹抹淺笑 提交于 2019-12-02 19:53:18
问题 I would like to serialize an object to an XML of this form with XStream. <node att="value">text</node> There already is a solution for this in StackOverflow here: XStream : node with attributes and text node? but it won't work for me since I am restricted to XStream 1.3.1. I found @XStreamConverter(value=ToAttributedValueConverter.class, strings={"content"}) which does exactly what I want in a simple way but it is not available in XStream 1.3.1. Is there a nicer way to solve this issue with 1

How to make XStream skip unmapped tags when parsing XML?

时光怂恿深爱的人放手 提交于 2019-12-02 18:14:05
I have a large XML document that I want to convert to a Java bean. It has a lot of tags and attributes, but I'm interested only in a handful of those. Unfurtounately, it seems that XStream forces you to declare a property in that bean for each and every tag that may ever be in that XML. Is there a way around this? Somu Initialize XStream as shown below to ignore fields that are not defined in your bean. XStream xstream = new XStream() { @Override protected MapperWrapper wrapMapper(MapperWrapper next) { return new MapperWrapper(next) { @Override public boolean shouldSerializeMember(Class