com.cohere.api.core.ObjectMappers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cohere-java Show documentation
Show all versions of cohere-java Show documentation
The official Java library for Cohere's API.
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.cohere.api.core;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.io.IOException;
public final class ObjectMappers {
public static final ObjectMapper JSON_MAPPER = JsonMapper.builder()
.addModule(new Jdk8Module())
.addModule(new JavaTimeModule())
.addModule(DateTimeDeserializer.getModule())
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.build();
private ObjectMappers() {}
public static String stringify(Object o) {
try {
return JSON_MAPPER
.setSerializationInclusion(JsonInclude.Include.ALWAYS)
.writerWithDefaultPrettyPrinter()
.writeValueAsString(o);
} catch (IOException e) {
return o.getClass().getName() + "@" + Integer.toHexString(o.hashCode());
}
}
}