View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.service.impl;
17  
18  import java.util.ArrayList;
19  
20  import org.kuali.rice.krad.service.util.DateTimeConverter;
21  
22  import com.thoughtworks.xstream.XStream;
23  import com.thoughtworks.xstream.mapper.MapperWrapper;
24  
25  /**
26   * Service implementation for the XmlObjectSerializer structure. This is the default implementation that gets
27   * delivered with Kuali. It utilizes the XStream open source libraries and framework
28   *
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class XmlObjectSerializerIgnoreMissingFieldsServiceImpl extends XmlObjectSerializerServiceImpl {
32  
33  	public XmlObjectSerializerIgnoreMissingFieldsServiceImpl() {
34  
35          xstream = new XStream(new ProxyAwareJavaReflectionProvider()) {
36              @Override
37              protected MapperWrapper wrapMapper(MapperWrapper next) {
38                  return new MapperWrapper(next) {
39                      @Override
40                      public boolean shouldSerializeMember(Class definedIn,
41                              String fieldName) {
42                          if (definedIn == Object.class) {
43                              return false;
44                          }
45                        return super.shouldSerializeMember(definedIn, fieldName);
46                     }
47                 };
48             }
49         };
50  
51  		xstream.registerConverter(new ProxyConverter(xstream.getMapper(), xstream.getReflectionProvider() ));
52          try {
53          	Class<?> objListProxyClass = Class.forName("org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl");
54              xstream.addDefaultImplementation(ArrayList.class, objListProxyClass);
55          } catch ( Exception ex ) {
56          	// Do nothing - this will blow if the OJB class does not exist, which it won't in some installs
57          }
58          xstream.registerConverter(new DateTimeConverter());
59  	}
60  
61  }