summaryrefslogtreecommitdiff
path: root/src/main/java/com/p4square/ccbapi/LocalDateTimeXmlAdapter.java
blob: f6ee565b30687f204f613c3939322c06dcad143d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.p4square.ccbapi;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * XmlAdapter implementation to convert CCB dates to LocalDateTime.
 *
 * Note that the datetime format used by CCB is not ISO-8601 formatted.
 */
public class LocalDateTimeXmlAdapter extends XmlAdapter<String, LocalDateTime> {

    private static final DateTimeFormatter FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public LocalDateTime unmarshal(final String value) throws Exception {
        return LocalDateTime.parse(value, FORMAT);
    }

    @Override
    public String marshal(final LocalDateTime value) throws Exception {
        return value.format(FORMAT);
    }

}