All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.sourcegroove.jackson.module.serialization.LocalDateTimeDeserializer Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
package com.github.sourcegroove.jackson.module.serialization;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.github.sourcegroove.jackson.module.DateRepresentation;
import com.github.sourcegroove.jackson.module.DateRepresentationType;

import java.io.IOException;
import java.time.LocalDateTime;

public class LocalDateTimeDeserializer extends JsonDeserializer {
    private DateRepresentationType type;
    public LocalDateTimeDeserializer(DateRepresentationType type){
        this.type = type;
    }
    @Override
    public LocalDateTime deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException {
        return parser.hasToken(JsonToken.VALUE_STRING) || parser.hasToken(JsonToken.VALUE_NUMBER_INT) ? 
                new DateRepresentation(this.type).of(parser.getValueAsString()).toLocalDateTime() : null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy