dev.fitko.fitconnect.client.zbp.ObjectMapperProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of client Show documentation
Show all versions of client Show documentation
Library that provides client access to the FIT-Connect api-endpoints for sending, subscribing and
routing
The newest version!
package dev.fitko.fitconnect.client.zbp;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
public class ObjectMapperProvider {
public static ObjectMapper createObjectMapper() {
return new ObjectMapper()
.registerModule(new SimpleModule().addSerializer(new CreateDateSerializer()))
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
private static class CreateDateSerializer extends StdSerializer {
private static final DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendInstant(3).toFormatter();
protected CreateDateSerializer() {
super(Instant.class);
}
@Override
public void serialize(Instant instant, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException {
String formattedInstant = formatter.format(instant);
jsonGenerator.writeString(formattedInstant);
}
}
}