public final class XmlUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
BASE_ATTRIBUTE |
static String |
CONTEXT_BASE |
static String |
CONTEXT_NEAR_CLASS
Resource-related context values. |
static String |
NEAR_CLASS_ATTRIBUTE
Resource attributes. |
static String |
PATH_ATTRIBUTE |
static String |
URL_ATTRIBUTE |
| Modifier and Type | Method and Description |
|---|---|
static void |
addImplicitArray(Class type,
String field)
Adds an implicit array.
|
static void |
addImplicitArray(Class type,
String field,
String itemName)
Adds an implicit array which is used for all items of the given element name defined by itemName.
|
static <T extends AliasProvider> |
alias(Class<T> aliasProvider)
Calls static "provideAliases" method on a class that implements AliasProvider.
|
static void |
alias(String name,
Class type)
Alias a Class to a shorter name to be used in XML elements.
|
static <T> T |
fromXML(InputStream input)
Returns Object deserialized from XML content.
|
static <T> T |
fromXML(InputStream input,
Object root)
Returns Object deserialized from XML content.
|
static <T> T |
fromXML(InputStream input,
XStreamContext context)
Returns Object deserialized from XML content.
|
static <T> T |
fromXML(Reader reader)
Returns Object deserialized from XML content.
|
static <T> T |
fromXML(Reader reader,
Object root)
Returns Object deserialized from XML content.
|
static <T> T |
fromXML(Reader reader,
XStreamContext context)
Returns Object deserialized from XML content.
|
static <T> T |
fromXML(Resource resource)
Returns Object deserialized from XML text.
|
static <T> T |
fromXML(Resource resource,
Object root)
Returns Object deserialized from XML text.
|
static <T> T |
fromXML(Resource resource,
XStreamContext context)
Returns Object deserialized from XML text.
|
static <T> T |
fromXML(String xml)
Returns Object deserialized from XML content.
|
static <T> T |
fromXML(String xml,
Object root)
Returns Object deserialized from XML content.
|
static <T> T |
fromXML(String xml,
XStreamContext context)
Returns Object deserialized from XML content.
|
static com.thoughtworks.xstream.XStream |
getXStream()
Returns global XStream instance configured with all required aliases and converters.
|
static boolean |
isAliasJdkClasses()
|
static void |
omitField(Class type,
String field)
Prevents field from being serialized.
|
static void |
processAnnotations(Class type)
Process the annotations of the given type and configure the XStream.
|
static void |
processAnnotations(Class[] types)
Process the annotations of the given types and configure the XStream.
|
static Resource |
readResource(com.thoughtworks.xstream.io.HierarchicalStreamReader reader,
com.thoughtworks.xstream.converters.UnmarshallingContext context,
com.thoughtworks.xstream.mapper.Mapper mapper)
Returns
Resource based on the available attributes in the current node. |
static void |
registerConverter(com.thoughtworks.xstream.converters.Converter converter)
Adds a new converter into converters registry.
|
static void |
registerConverter(com.thoughtworks.xstream.converters.SingleValueConverter converter)
Adds a new converter into converters registry.
|
static void |
setAliasJdkClasses(boolean alias)
|
static String |
toXML(Object obj)
Returns Object serialized into XML.
|
static void |
toXML(Object obj,
File file)
Serializes Object into XML and writes it into specified file.
|
static void |
toXML(Object obj,
com.thoughtworks.xstream.io.HierarchicalStreamWriter writer)
Serializes Object into XML and writes it using a specified HierarchicalStreamWriter
|
static void |
toXML(Object obj,
OutputStream out)
Serializes Object into XML and writes it using a specified OutputStream.
|
static void |
toXML(Object obj,
String file)
Serializes Object into XML and writes it into specified file.
|
static void |
toXML(Object obj,
Writer out)
Serializes Object into XML and writes it using a specified Writer.
|
static void |
useAttributeFor(Class type,
String field)
Use an attribute for a field declared in a specific type.
|
public static final String NEAR_CLASS_ATTRIBUTE
Resource attributes.public static final String BASE_ATTRIBUTE
public static final String PATH_ATTRIBUTE
public static final String URL_ATTRIBUTE
public static final String CONTEXT_NEAR_CLASS
Resource-related context values.public static final String CONTEXT_BASE
@NotNull public static com.thoughtworks.xstream.XStream getXStream()
public static boolean isAliasJdkClasses()
true if should use aliases for standard JDK classes are used, false otherwisepublic static void setAliasJdkClasses(boolean alias)
alias - whether or not aliases for standard JDK classes should be usedpublic static void processAnnotations(@NotNull Class type)
type - the type with XStream annotationspublic static void processAnnotations(@NotNull Class[] types)
types - the types with XStream annotationspublic static void alias(@NotNull String name, @NotNull Class type)
name - Short nametype - Type to be aliasedpublic static void omitField(@NotNull Class type, @NotNull String field)
type - class owning the fieldfield - name of the fieldpublic static void useAttributeFor(@NotNull Class type, @NotNull String field)
type - the name of the fieldfield - the Class containing such fieldpublic static void addImplicitArray(@NotNull Class type, @NotNull String field)
type - class owning the implicit arrayfield - name of the array fieldpublic static void addImplicitArray(@NotNull Class type, @NotNull String field, @NotNull String itemName)
type - class owning the implicit arrayfield - name of the array field in the ownerTypeitemName - alias name of the itemspublic static void registerConverter(@NotNull com.thoughtworks.xstream.converters.Converter converter)
converter - the new converterpublic static void registerConverter(@NotNull com.thoughtworks.xstream.converters.SingleValueConverter converter)
converter - the new converterpublic static <T extends AliasProvider> void alias(@NotNull Class<T> aliasProvider)
T - specific class typealiasProvider - AliasProvider ancestor classpublic static <T> T fromXML(@NotNull String xml)
T - read object typexml - XML contentpublic static <T> T fromXML(@NotNull String xml, @NotNull Object root)
T - read object typexml - XML contentroot - root Objectpublic static <T> T fromXML(@NotNull String xml, @Nullable XStreamContext context)
T - read object typexml - XML contentcontext - unmarshalling context datapublic static <T> T fromXML(@NotNull Resource resource)
T - read object typeresource - Resourcepublic static <T> T fromXML(@NotNull Resource resource, @NotNull Object root)
public static <T> T fromXML(@NotNull Resource resource, @Nullable XStreamContext context)
T - read object typeresource - Resourcecontext - unmarshalling context datapublic static <T> T fromXML(@NotNull InputStream input)
T - read object typeinput - XML text sourcepublic static <T> T fromXML(@NotNull InputStream input, @NotNull Object root)
T - read object typeinput - XML text sourceroot - root Objectpublic static <T> T fromXML(@NotNull InputStream input, @Nullable XStreamContext context)
T - read object typeinput - XML text sourcecontext - unmarshalling context datapublic static <T> T fromXML(@NotNull Reader reader)
T - read object typereader - XML text sourcepublic static <T> T fromXML(@NotNull Reader reader, @NotNull Object root)
T - read object typereader - XML text sourceroot - root Objectpublic static <T> T fromXML(@NotNull Reader reader, @Nullable XStreamContext context)
T - read object typereader - XML text sourcecontext - unmarshalling context datapublic static void toXML(@NotNull Object obj, @NotNull String file)
obj - object to serializefile - output filepublic static void toXML(@NotNull Object obj, @NotNull File file)
obj - object to serializefile - output file@NotNull public static String toXML(@NotNull Object obj)
obj - object to serializepublic static void toXML(@NotNull Object obj, @NotNull Writer out)
obj - object to serializeout - output writerpublic static void toXML(@NotNull Object obj, @NotNull OutputStream out)
obj - object to serializeout - output streampublic static void toXML(@NotNull Object obj, @NotNull com.thoughtworks.xstream.io.HierarchicalStreamWriter writer)
obj - object to serializewriter - hierarchical stream writer@NotNull public static Resource readResource(@NotNull com.thoughtworks.xstream.io.HierarchicalStreamReader reader, @NotNull com.thoughtworks.xstream.converters.UnmarshallingContext context, @NotNull com.thoughtworks.xstream.mapper.Mapper mapper)
Resource based on the available attributes in the current node.reader - HierarchicalStreamReadercontext - UnmarshallingContextmapper - MapperResource based on the available attributes in the current nodeCopyright © 2020. All rights reserved.