Java Gson 可以生成 XML 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21825263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can Gson produce XML?
提问by paj28
Is it possible to use the Gsonlibrary to produce XML?
是否可以使用Gson库来生成 XML?
I am aware the gson-xmlcan read XML into Gson. Is there a library that lets you go the other way?
我知道gson-xml可以将 XML 读入 Gson。有没有可以让你走另一条路的图书馆?
My motivation is that I have a complex application that needs to serialise to both JSON and XML and I'd ideally like to use a single serialisation library.
我的动机是我有一个复杂的应用程序,需要同时序列化为 JSON 和 XML,而且我希望使用单个序列化库。
回答by yanana
I don't know if the library can serialize to both JSON
and XML
.
But from the same model-object, you can do it, e.g. Hymanson-dataformat-xmlas XML
-Serializer
and Hymansonas JSON
-serializer. And, if your application is complex enough to modularise,
you should encapsulate serialization layer.
我不知道该库是否可以同时序列化为JSON
和XML
. 但是从同一个模型对象,你可以做到,例如Hymanson-XML
dataformat -xml作为-Serializer 和Hymanson作为JSON
-serializer。而且,如果您的应用程序复杂到可以模块化,您应该封装序列化层。