com.mycompany.ajaxandxml.ws.ReleasedAdapter.java Source code

Java tutorial

Introduction

Here is the source code for com.mycompany.ajaxandxml.ws.ReleasedAdapter.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.ajaxandxml.ws;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

/**
 *
 * @author vasigorc
 */
public class ReleasedAdapter extends XmlAdapter<String, LocalDate> {
    private static final DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");

    @Override
    public LocalDate unmarshal(String v) throws Exception {
        return LocalDate.parse(v, dateFormatter);
    }

    @Override
    public String marshal(LocalDate v) throws Exception {
        return v.getYear() + "-" + v.getMonthOfYear() + "-" + v.getDayOfMonth();
    }

}