com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bitpay_sdk Show documentation
Show all versions of bitpay_sdk Show documentation
Full implementation of the BitPay Payment Gateway. This library implements BitPay's Cryptographically
Secure RESTful API.
/*
* Copyright (c) 2019 BitPay.
* All rights reserved.
*/
package com.bitpay.sdk.util.serializer;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
public class ZonedDateTimeToIso8601Serializer extends JsonSerializer {
private static final DateTimeFormatter DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSX");
/**
* This method deserialize ZonedDateTime to format yyyy-mm-ddThh:mm:ssZ.
*
* @param zonedDateTime ZonedDateTime
* @param jsonGenerator JsonGenerator
* @param serializerProvider SerializerProvider
* @throws IOException IOException
*/
@Override
public void serialize(
ZonedDateTime zonedDateTime,
JsonGenerator jsonGenerator,
SerializerProvider serializerProvider
) throws IOException {
jsonGenerator.writeString(zonedDateTime.format(DATE_TIME_FORMATTER));
}
}