Mavn Package:
<Dependency>
<groupId>Com.thoughtworks.xstream</groupId>
<Artifactid>XStream</Artifactid>
<version>1.4.9</version>
</Dependency>
Filtering Unrecognized nodes
PackageCommon
ImportCom.thoughtworks.xstream.XStream;
ImportCom.thoughtworks.xstream.mapper.MapperWrapper;
Public classEtlxstreamextendsXStream {
/*
* (Non-javadoc)
*
* @see
* Com.thoughtworks.xstream.xstream#wrapmapper
*/
@Override
protectedMapperwrapper Wrapmapper (Mapperwrapper next) {
return newMapperwrapper (Next) {
/*
* (Non-javadoc)
*
* @see
* Com.thoughtworks.xstream.mapper.mapperwrapper#shouldserializemember
*/
@Override
Public BooleanShouldserializemember (@SuppressWarnings("Rawtypes") Class Definedin, String fieldName) {
//Unrecognized node, skimmed.
if(Definedin = = Object.class){
Try{
return This. Realclass (fieldName)! =NULL;
}Catch(Exception e) {
return False;
}
}Else{
return Super. Shouldserializemember (Definedin, fieldName);
}
}
};
}
}
Xmlhelper Package Class
PackageCommon
ImportJava.io.InputStream;
ImportJava.lang.Class;
ImportJava.util.HashMap;
ImportJava.util.Map;
ImportJava.util.Map.Entry;
Public classXmlhelper {
Public Static<T> String ToXml (TObject, hashmap<string, class> map) {
Etlxstream XStream =Getxstream(map);
for(Entry<string, Class> entry:map.entrySet ()) {
Xstream.alias (Entry.getkey (), Entry.getvalue ());
}
returnXstream.toxml (object);
}
Public Static<T>TToobject (String XML, hashmap<string, class> map) {
Etlxstream XStream =Getxstream(map);
TObject = (T) xstream.fromxml (XML);
returnObject
}
Public Static<T>TToobject (InputStream stream, hashmap<string, class> map) {
Etlxstream XStream =Getxstream(map);
TObject = (T) Xstream.fromxml (stream);
returnObject
}
private staticEtlxstream Getxstream (hashmap<string, class> map) {
Etlxstream XStream =NewEtlxstream ();
for(Entry<string, Class> entry:map.entrySet ()) {
Xstream.alias (Entry.getkey (), Entry.getvalue ());
}
returnXStream
}
}
Use of JAVA XStream