Skip to content

Instantly share code, notes, and snippets.

@ghusta
Created January 13, 2014 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghusta/8403885 to your computer and use it in GitHub Desktop.
Save ghusta/8403885 to your computer and use it in GitHub Desktop.
LocalDateAdapter, useful to convert String to Joda Time's LocalDate and conversely, for use with JAXB 2.0. Can be used when customizing XML Schema to Java Representation Binding (XJC).
package xml.adapters.jodatime;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import org.joda.time.LocalDate;
/**
* LocalDateAdapter, useful to convert String to Joda Time's LocalDate and conversely, for use with JAXB 2.0.
* <br>
* Can be used when customizing XML Schema to Java Representation Binding (XJC).
*
* @see org.joda.time.LocalDate
*/
public class LocalDateAdapter
extends XmlAdapter<String, LocalDate>
{
public LocalDate unmarshal(String v) throws Exception
{
return new LocalDate(v);
}
public String marshal(LocalDate v) throws Exception
{
return v.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment