com.github.sourcegroove.jackson.module.serialization.LocalDateTimeDeserializer 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.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