com.github.sourcegroove.jackson.module.serialization.DateDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-simple-date-module Show documentation
Show all versions of jackson-simple-date-module Show documentation
Layout driven spring batch item readers and writers
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