1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.service.impl;
17
18 import com.thoughtworks.xstream.XStream;
19 import com.thoughtworks.xstream.mapper.MapperWrapper;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl;
23 import org.kuali.rice.krad.service.PersistenceService;
24 import org.kuali.rice.krad.util.DateTimeConverter;
25
26 import java.util.ArrayList;
27
28
29
30
31
32 public class XmlObjectSerializerIgnoreMissingFieldsServiceImpl extends XmlObjectSerializerServiceImpl {
33 private static final Log LOG = LogFactory.getLog(XmlObjectSerializerIgnoreMissingFieldsServiceImpl.class);
34
35 private PersistenceService persistenceService;
36
37 private XStream xstream;
38
39 public XmlObjectSerializerIgnoreMissingFieldsServiceImpl() {
40
41 xstream = new XStream(new ProxyAwareJavaReflectionProvider()) {
42 @Override
43 protected MapperWrapper wrapMapper(MapperWrapper next) {
44 return new MapperWrapper(next) {
45 @Override
46 public boolean shouldSerializeMember(Class definedIn,
47 String fieldName) {
48 if (definedIn == Object.class) {
49 return false;
50 }
51 return super.shouldSerializeMember(definedIn, fieldName);
52 }
53 };
54 }
55 };
56
57 xstream.registerConverter(new ProxyConverter(xstream.getMapper(), xstream.getReflectionProvider() ));
58 xstream.addDefaultImplementation(ArrayList.class, ListProxyDefaultImpl.class);
59 xstream.registerConverter(new DateTimeConverter());
60 }
61
62
63
64
65
66
67 public Object fromXml(String xml) {
68 if ( LOG.isDebugEnabled() ) {
69 LOG.debug( "fromXml() : \n" + xml );
70 }
71 if ( xml != null ) {
72 xml = xml.replaceAll( "--EnhancerByCGLIB--[0-9a-f]{0,8}", "" );
73 }
74 return xstream.fromXML(xml);
75 }
76 }