001/** 002 * Copyright 2005-2014 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 */ 016/** 017 * This is a utility converter class for use with XStream serializers. This was written to deal with an issue 018 * resulting from the use of JODA-Time where unmarshalling of XML was failing. 019 * This applies to only DateTime.class fields. 020 */ 021package org.kuali.rice.krad.service.util; 022 023import com.thoughtworks.xstream.converters.SingleValueConverter; 024import org.joda.time.DateTime; 025import org.joda.time.format.ISODateTimeFormat; 026 027/** 028 * @author Kuali Rice Team (rice.collab@kuali.org) 029 */ 030public class DateTimeConverter implements SingleValueConverter { 031 public boolean canConvert(Class clazz) { 032 return clazz.equals(DateTime.class); 033 } 034 035 @Override 036 public String toString(Object obj) { 037 return obj.toString(); 038 } 039 040 @Override 041 public Object fromString(String value) { 042 return ISODateTimeFormat.dateTimeParser().parseDateTime(value); 043 } 044}