001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.service.impl; 017 018import java.util.ArrayList; 019 020import org.kuali.rice.krad.service.util.DateTimeConverter; 021 022import com.thoughtworks.xstream.XStream; 023import com.thoughtworks.xstream.mapper.MapperWrapper; 024 025/** 026 * Service implementation for the XmlObjectSerializer structure. This is the default implementation that gets 027 * delivered with Kuali. It utilizes the XStream open source libraries and framework 028 * 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 */ 031public class XmlObjectSerializerIgnoreMissingFieldsServiceImpl extends XmlObjectSerializerServiceImpl { 032 033 public XmlObjectSerializerIgnoreMissingFieldsServiceImpl() { 034 035 xstream = new XStream(new ProxyAwareJavaReflectionProvider()) { 036 @Override 037 protected MapperWrapper wrapMapper(MapperWrapper next) { 038 return new MapperWrapper(next) { 039 @Override 040 public boolean shouldSerializeMember(Class definedIn, 041 String fieldName) { 042 if (definedIn == Object.class) { 043 return false; 044 } 045 return super.shouldSerializeMember(definedIn, fieldName); 046 } 047 }; 048 } 049 }; 050 051 xstream.registerConverter(new ProxyConverter(xstream.getMapper(), xstream.getReflectionProvider() )); 052 try { 053 Class<?> objListProxyClass = Class.forName("org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl"); 054 xstream.addDefaultImplementation(ArrayList.class, objListProxyClass); 055 } catch ( Exception ex ) { 056 // Do nothing - this will blow if the OJB class does not exist, which it won't in some installs 057 } 058 xstream.registerConverter(new DateTimeConverter()); 059 } 060 061}