[英]Drop-in replacement for java.beans.XMLEncoder
I've got lots XSL transforms that rely on the java.beans.XMLEncoder
XML format, and I'm wondering if I can find a drop-in replacement lib that has better performance. 我有很多XSL转换都依赖于java.beans.XMLEncoder
XML格式,我想知道是否可以找到性能更好的嵌入式替换库。 I've looked at XStream but its serialization format is different. 我看过XStream,但其序列化格式却不同。
I'm looking to replace it as I'm working with a legacy codebase that has a forked version of XMLEncoder
and I'd like to return it to something more standard, but java.beans.XMLEncoder
has much worse performance. 我正在替换它,因为我正在使用具有XMLEncoder
分支版本的遗留代码库,并且希望将其恢复为更标准的名称,但是java.beans.XMLEncoder
性能要差得多。
For a class Person
(with appropriate getters and setters): 对于班级Person
(具有适当的获取器和设置器):
public class Person {
private String name;
private List<String> favoriteColors;
private Date birthDate;
private int age;
}
XMLEncoder
produces XML like the following: XMLEncoder
产生如下的XML:
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.8.0_66" class="java.beans.XMLDecoder">
<object class="Person" id="Person0">
<void property="age">
<int>40</int>
</void>
<void property="birthDate">
<object class="java.util.Date">
<long>175064400000</long>
</object>
</void>
<void property="favoriteColors">
<void method="add">
<string>red</string>
</void>
<void method="add">
<string>green</string>
</void>
</void>
<void property="name">
<string>John Doe</string>
</void>
</object>
</java>
I'm guessing it would be possible to create a bunch of XStream Converters to approximate the format but I'm wondering if there's an easier solution before I head down that rabbit hole. 我猜想可能会创建一堆XStream Converter来近似格式,但是我想知道在解决这个难题之前是否有更简单的解决方案。
In case anyone else runs across this later, implementing via XStream will get you there as long as you don't care about the order of elements. 万一以后还有其他人遇到这个问题,只要您不关心元素的顺序,通过XStream实施将使您到达那里。 You could probably do a deeper implementation that allows you to control the order of the elements, but I ended up scrapping the idea and I'm just going to deal with it until I can re-write the code in question. 您可能可以做一个更深的实现,允许您控制元素的顺序,但是我最终放弃了这个想法,我将继续处理它,直到可以重新编写有问题的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.