public class JacksonSingleton extends Object implements org.wisdom.api.content.JacksonModuleRepository, org.wisdom.api.content.Json, org.wisdom.api.content.Xml
Json
and Xml services.
This class manages Jackson module dynamically, and recreates a JSON Mapper and XML mapper every time a module arrives
or leaves.| Modifier and Type | Field and Description |
|---|---|
private DocumentBuilderFactory |
factory
The document builder factory used to create new document.
|
private Object |
lock
An object used as lock.
|
private static org.slf4j.Logger |
LOGGER
The logger.
|
private com.fasterxml.jackson.databind.ObjectMapper |
mapper
The current object mapper.
|
private Set<com.fasterxml.jackson.databind.Module> |
modules
The current set of registered modules.
|
private com.fasterxml.jackson.dataformat.xml.XmlMapper |
xml
The current object mapper.
|
| Constructor and Description |
|---|
JacksonSingleton() |
| Modifier and Type | Method and Description |
|---|---|
Document |
fromInputStream(InputStream stream,
Charset encoding)
Builds a new XML Document from the given input stream.
|
<A> A |
fromJson(com.fasterxml.jackson.databind.JsonNode json,
Class<A> clazz)
Converts a JsonNode to a Java value.
|
<A> A |
fromJson(String json,
Class<A> clazz)
Converts a Json String to a Java value.
|
Document |
fromString(String xml)
Builds a new XML Document from the given (xml) string.
|
<A> A |
fromXML(Document document,
Class<A> clazz)
Builds a new instance of the given class clazz from the given XML document.
|
<A> A |
fromXML(String xml,
Class<A> clazz)
Builds a new instance of the given class clazz from the given XML string.
|
void |
invalidate()
Stops the JSON and XML management.
|
com.fasterxml.jackson.databind.ObjectMapper |
mapper()
Gets the current mapper.
|
com.fasterxml.jackson.databind.node.ArrayNode |
newArray()
Creates a new JSON Array.
|
Document |
newDocument()
Creates a new document.
|
com.fasterxml.jackson.databind.node.ObjectNode |
newObject()
Creates a new JSON Object.
|
com.fasterxml.jackson.databind.JsonNode |
parse(InputStream stream)
Parses a stream representing a json, and return it as a JsonNode.
|
com.fasterxml.jackson.databind.JsonNode |
parse(String src)
Parses a String representing a json, and return it as a JsonNode.
|
private void |
rebuildMappers() |
void |
register(com.fasterxml.jackson.databind.Module module)
Registers a new Jackson Module.
|
private void |
setMappers(com.fasterxml.jackson.databind.ObjectMapper mapper,
com.fasterxml.jackson.dataformat.xml.XmlMapper xml)
Sets the object mapper.
|
String |
stringify(Document document)
Retrieves the string form of the given XML document.
|
String |
stringify(com.fasterxml.jackson.databind.JsonNode json)
Converts a JsonNode to its string representation.
|
com.fasterxml.jackson.databind.JsonNode |
toJson(Object data)
Converts an object to JsonNode.
|
String |
toJsonP(String callback,
Object data)
Gets the JSONP response for the given callback and value.
|
void |
unregister(com.fasterxml.jackson.databind.Module module)
Un-registers a JSON Module.
|
void |
validate()
Starts the JSON and XML support.
|
com.fasterxml.jackson.dataformat.xml.XmlMapper |
xmlMapper()
Gets the current XML mapper.
|
private final Object lock
private com.fasterxml.jackson.databind.ObjectMapper mapper
private com.fasterxml.jackson.dataformat.xml.XmlMapper xml
private DocumentBuilderFactory factory
private static final org.slf4j.Logger LOGGER
private Set<com.fasterxml.jackson.databind.Module> modules
public com.fasterxml.jackson.databind.ObjectMapper mapper()
mapper in interface org.wisdom.api.content.Jsonpublic com.fasterxml.jackson.databind.JsonNode toJson(Object data)
toJson in interface org.wisdom.api.content.Jsondata - Value to convert in Json.RuntimeException - if the JSON Node cannot be createdpublic String toJsonP(String callback, Object data)
toJsonP in interface org.wisdom.api.content.Jsoncallback - the callback namedata - the data to transform to jsonpublic <A> A fromJson(com.fasterxml.jackson.databind.JsonNode json,
Class<A> clazz)
fromJson in interface org.wisdom.api.content.Jsonjson - Json value to convert.clazz - Expected Java value type.RuntimeException - if the object cannot be createdpublic <A> A fromJson(String json, Class<A> clazz)
fromJson in interface org.wisdom.api.content.Jsonjson - Json string to convert.clazz - Expected Java value type.RuntimeException - if the object cannot be createdpublic String stringify(com.fasterxml.jackson.databind.JsonNode json)
stringify in interface org.wisdom.api.content.Jsonjson - the json nodeRuntimeException - if the String form cannot be createdpublic com.fasterxml.jackson.databind.JsonNode parse(String src)
parse in interface org.wisdom.api.content.Jsonsrc - the JSON StringRuntimeException - if the given string is not a valid JSON Stringpublic com.fasterxml.jackson.databind.JsonNode parse(InputStream stream)
parse in interface org.wisdom.api.content.Jsonstream - the JSON streamRuntimeException - if the given stream is not a valid JSON Stringpublic com.fasterxml.jackson.databind.node.ObjectNode newObject()
newObject in interface org.wisdom.api.content.Jsonpublic com.fasterxml.jackson.databind.node.ArrayNode newArray()
newArray in interface org.wisdom.api.content.Jsonpublic void validate()
private void setMappers(com.fasterxml.jackson.databind.ObjectMapper mapper,
com.fasterxml.jackson.dataformat.xml.XmlMapper xml)
mapper - the object mapper to usepublic void invalidate()
public void register(com.fasterxml.jackson.databind.Module module)
register in interface org.wisdom.api.content.JacksonModuleRepositorymodule - the module to registerprivate void rebuildMappers()
public void unregister(com.fasterxml.jackson.databind.Module module)
unregister in interface org.wisdom.api.content.JacksonModuleRepositorymodule - the modulepublic com.fasterxml.jackson.dataformat.xml.XmlMapper xmlMapper()
xmlMapper in interface org.wisdom.api.content.Xmlpublic Document fromString(String xml) throws IOException
fromInputStream(java.io.InputStream, java.nio.charset.Charset) that let you set the encoding.fromString in interface org.wisdom.api.content.Xmlxml - the xml to parse, must not be nullIOException - if the given string is not a valid XML documentpublic Document fromInputStream(InputStream stream, Charset encoding) throws IOException
fromInputStream in interface org.wisdom.api.content.Xmlstream - the input stream, must not be nullencoding - the encoding, if null, UTF-8 is used.IOException - if the given stream is not a valid XML document,
or if the given encoding is not supported.public <A> A fromXML(Document document, Class<A> clazz)
fromXML in interface org.wisdom.api.content.Xmldocument - the XML documentclazz - the class of the instance to constructpublic <A> A fromXML(String xml, Class<A> clazz)
fromXML in interface org.wisdom.api.content.Xmlxml - the XML stringclazz - the class of the instance to constructpublic String stringify(Document document)
stringify in interface org.wisdom.api.content.Xmldocument - the XML document, must not be nullpublic Document newDocument()
newDocument in interface org.wisdom.api.content.XmlCopyright © 2013–2014 Wisdom Framework. All rights reserved.