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

com.github.sourcegroove.jackson.module.serialization.DateDeserializer 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.util.Date;

public class DateDeserializer extends JsonDeserializer {
    private DateRepresentationType type;
    public DateDeserializer(DateRepresentationType type){
        this.type = type;
    }
    @Override
    public Date 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()).toDate() : null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy