com.devcraftsman.blog.post.api.util.ISOLocalDateTimeSerializer.java Source code

Java tutorial

Introduction

Here is the source code for com.devcraftsman.blog.post.api.util.ISOLocalDateTimeSerializer.java

Source

package com.devcraftsman.blog.post.api.util;

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.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Created by devcraftsman on 4/1/16.
 * ----------------------------------------------------
 * This software is licensed under the Apache 2 license
 * see: [http://www.apache.org/licenses/LICENSE-2.0]
 **/
public class ISOLocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {

    @Override
    public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers)
            throws IOException {
        if (value != null) {
            gen.writeString(value.format(DateTimeFormatter.ISO_DATE_TIME));
        }

    }
}