Hi i need to parse date format passed to webservice to specific format.
i tried below changes in application-context.xml but still no luck with it. Any help will be deeply appreciated. thanks
HTML Code:<mvc:annotation-driven conversion-service="conversionService" /> <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> <property name="converters"> <set> <bean class="ws.marshaller.DateFormatter"/> </set> </property> </bean>HTML Code:package ws.marshaller; import java.text.DateFormat ; import java.text.ParseException ; import java.text.SimpleDateFormat ; import java.util.Date ; import java.util.Locale ; import org.springframework.format.Formatter ; public final class DateFormatter implements Formatter<Date> { private String pattern="yyyy-MM-dd'T'hh:mmss"; public DateFormatter(String pattern) { this.pattern = pattern; } public String print(Date date, Locale locale) { if (date == null) { return ""; } return getDateFormat(locale).format(date); } public Date parse(String formatted, Locale locale) throws ParseException { if (formatted.length() == 0) { return null; } return getDateFormat(locale).parse(formatted); } protected DateFormat getDateFormat(Locale locale) { DateFormat dateFormat = new SimpleDateFormat(this.pattern, locale); dateFormat.setLenient(false); return dateFormat; } }


Reply With Quote