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

Java tutorial

Introduction

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

Source

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

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

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 ISOLocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {

    @Override
    public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        if (p.getText() != null)
            return LocalDateTime.parse(p.getText(), DateTimeFormatter.ISO_DATE_TIME);
        else
            return null;
    }
}