2424import org .simpleframework .xml .Serializer ;
2525import org .simpleframework .xml .convert .AnnotationStrategy ;
2626import org .simpleframework .xml .core .Persister ;
27+ import org .simpleframework .xml .filter .Filter ;
2728import org .simpleframework .xml .stream .Format ;
2829
2930/** XML marshaller and unmarshaller. */
3031public class Xml {
32+ private static final Filter noopFilter =
33+ new Filter () {
34+ @ Override
35+ public String replace (String name ) {
36+ return null ;
37+ }
38+ };
39+
3140 /**
3241 * This marshal method will traverse the provided object checking for field annotations in order
3342 * to compose the XML data.
3443 */
3544 public static String marshal (Object source ) throws XmlParserException {
3645 try {
37- Serializer serializer = new Persister (new AnnotationStrategy (), new Format (0 ));
46+ Serializer serializer = new Persister (new AnnotationStrategy (), noopFilter , new Format (0 ));
3847 StringWriter writer = new StringWriter ();
3948 serializer .write (source , writer );
4049 return writer .toString ();
@@ -49,7 +58,7 @@ public static String marshal(Object source) throws XmlParserException {
4958 */
5059 public static <T > T unmarshal (Class <? extends T > type , Reader source ) throws XmlParserException {
5160 try {
52- Serializer serializer = new Persister (new AnnotationStrategy ());
61+ Serializer serializer = new Persister (new AnnotationStrategy (), noopFilter );
5362 return serializer .read (type , source );
5463 } catch (Exception e ) {
5564 throw new XmlParserException (e );
@@ -62,7 +71,7 @@ public static <T> T unmarshal(Class<? extends T> type, Reader source) throws Xml
6271 */
6372 public static <T > T unmarshal (Class <? extends T > type , String source ) throws XmlParserException {
6473 try {
65- Serializer serializer = new Persister (new AnnotationStrategy ());
74+ Serializer serializer = new Persister (new AnnotationStrategy (), noopFilter );
6675 return serializer .read (type , new StringReader (source ));
6776 } catch (Exception e ) {
6877 throw new XmlParserException (e );
@@ -75,7 +84,7 @@ public static <T> T unmarshal(Class<? extends T> type, String source) throws Xml
7584 */
7685 public static boolean validate (Class type , String source ) throws XmlParserException {
7786 try {
78- Serializer serializer = new Persister (new AnnotationStrategy ());
87+ Serializer serializer = new Persister (new AnnotationStrategy (), noopFilter );
7988 return serializer .validate (type , source );
8089 } catch (Exception e ) {
8190 throw new XmlParserException (e );
0 commit comments