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

ph.com.nightowlstudios.entity.serializer.LocalDateDeserializer Maven / Gradle / Ivy

There is a newer version: 6.21.1
Show newest version
package ph.com.nightowlstudios.entity.serializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import java.io.IOException;
import java.time.LocalDate;

/**
 * @author Joseph Harvey Angeles - yev
 * @since 8/11/21
 **/
public class LocalDateDeserializer extends StdDeserializer {

    protected LocalDateDeserializer() {
        this(LocalDate.class);
    }

    protected LocalDateDeserializer(Class vc) {
        super(vc);
    }

    @Override
    public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        try {
            return LocalDate.parse(p.getText());
        } catch (NumberFormatException e) {
            return LocalDate.parse(LocalDate.now().toString());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy