com.fasterxml.jackson.jr.extension.javatime.LocalDateTimeValueWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-jr-extension-javatime Show documentation
Show all versions of jackson-jr-extension-javatime Show documentation
Jackson-jr extension that adds support for Java 8 Date/Time value types such as `java.time.LocalDateTime`
package com.fasterxml.jackson.jr.extension.javatime;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.jr.ob.api.ValueWriter;
import com.fasterxml.jackson.jr.ob.impl.JSONWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class LocalDateTimeValueWriter implements ValueWriter {
private final DateTimeFormatter formatter;
public LocalDateTimeValueWriter(DateTimeFormatter formatter) {
this.formatter = formatter;
}
@Override
public void writeValue(JSONWriter context, JsonGenerator g, Object value) throws IOException {
String localDateTimeString = ((LocalDateTime) value).format(formatter);
context.writeValue(localDateTimeString);
}
@Override
public Class> valueType() {
return LocalDateTime.class;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy