ankur-singhal 452070aa35 XStream- Object to Xml
Closing Review comments, test cases added.
2016-03-20 20:46:58 +05:30

29 lines
714 B
Java

package com.baeldung.utility;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.baeldung.pojo.Customer;
import com.thoughtworks.xstream.converters.SingleValueConverter;
public class MySingleValueConverter implements SingleValueConverter {
@Override
public boolean canConvert(Class clazz) {
return Customer.class.isAssignableFrom(clazz);
}
@Override
public Object fromString(String arg0) {
return null;
}
@Override
public String toString(Object obj) {
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
Date date = ((Customer) obj).getDob();
return ((Customer) obj).getFirstName() + "," + ((Customer) obj).getLastName() + "," + formatter.format(date);
}
}