Skip to content

Instantly share code, notes, and snippets.

@ghusta
Created January 15, 2014 09:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghusta/8433488 to your computer and use it in GitHub Desktop.
Save ghusta/8433488 to your computer and use it in GitHub Desktop.
LocalDateTimeAdapter, useful to convert String to Joda Time's LocalDateTime 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.LocalDateTime;
/**
* LocalDateTimeAdapter, useful to convert String to Joda Time's LocalDateTime 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.LocalDateTime
*/
public class LocalDateTimeAdapter
extends XmlAdapter<String, LocalDateTime>
{
public LocalDateTime unmarshal(String v) throws Exception
{
return new LocalDateTime(v);
}
public String marshal(LocalDateTime v) throws Exception
{
return v.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment