{#========================================== Spincast Jackson XML plugin ==========================================#} {% extends "../../layout.html" %} {% block sectionClasses %}plugins plugins-spincast-jackson-xml{% endblock %} {% block meta_title %}Plugins - Spincast Jackson XML{% endblock %} {% block meta_description %}Spincast Jackson XML plugin provides XML functionalities using Jackson.{% endblock %} {% block scripts %} {% endblock %} {% block body %}
The Spincast Jackson XML plugin provides XML functionalities
using Jackson. It contains an implementation
of the IXmlManager interface.
Most of the time, the IXmlManager interface is used directly from
the request context via the
xml() method or indirectly via
some methods on the response() add-on.
For example:
{% verbatim %}
public class AppController {
public void myHandler(IDefaultRequestContext context) {
// Create a Json object from a XML String, using the "xml()" add-on
IJsonObject jsonObj = context.xml().fromXml("<user></user>");
// Send an object as XML, using the "response()" add-on
context.response().sendXml(jsonObj);
}
}{% endverbatim %}
You can also directly inject the IXmlManager
instance where you need it in your application.
If you use the spincast-default artifact, this plugin is already installed so
you have nothing more to do!
If you start from scratch using the spincast-core artifact, you can use the
plugin by adding this artifact to your project:
<dependency>
<groupId>org.spincast</groupId>
<artifactId>spincast-plugins-jackson-xml</artifactId>
<version>{{spincastLatestStableVersion}}</version>
</dependency>
You then install the plugin's Guice module, by passing it to the Guice.createInjector(...) method:
Injector guice = Guice.createInjector(
new SpincastCoreGuiceModule(args),
new SpincastJacksonXmlPluginGuiceModule(IAppRequestContext.class)
// other modules...
);
... or by using the install(...) method from your custom Guice module:
public class AppModule extends SpincastCoreGuiceModule {
@Override
protected void configure() {
super.configure();
install(new SpincastJacksonXmlPluginGuiceModule(getRequestContextType()));
// other modules...
}
// ...
}
IXmlManager interface
String toXml(Object obj)
IJsonObject, its elements
of type "IJsonArray" will have a "isArray='true'" attribute
added. This way, the XML can be deserialized back to a
IJsonObject correctly.
String toXml(Object obj, boolean pretty)
IJsonObject fromXml(String xml)
IJsonObject. This
will correctly manage the XML generated by
toXml(), arrays included.
IJsonArray fromXmlToJsonArray(String xml)
IJsonArray. This
will correctly manage the XML generated by
toXml(), arrays included.
<T> T fromXml(String xml, Class<T> clazz)
IJsonObject to get the
arrays to work out of the box!
<T> T fromXmlToType(String xml, Type type)
IJsonObject to get the
arrays to work out of the box!
<T> T fromXmlInputStream(InputStream inputStream, Class<T> clazz)
IJsonObject to get the
arrays to work out of the box!