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 */ 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.util; 022 023import com.thoughtworks.xstream.converters.SingleValueConverter; 024import org.joda.time.DateTime; 025import org.joda.time.format.ISODateTimeFormat; 026 027public class DateTimeConverter implements SingleValueConverter { 028 public boolean canConvert(Class clazz) { 029 return clazz.equals(DateTime.class); 030 } 031 032 @Override 033 public String toString(Object obj) { 034 return obj.toString(); 035 } 036 037 @Override 038 public Object fromString(String value) { 039 return ISODateTimeFormat.dateTimeParser().parseDateTime(value); 040 } 041}