io.swagger.v3.parser.ObjectMapperFactory Maven / Gradle / Ivy
package io.swagger.v3.parser;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
public class ObjectMapperFactory {
public static ObjectMapper createJson() {
return createJson(true, true);
}
protected static ObjectMapper createJson(boolean includePathDeserializer, boolean includeResponseDeserializer) {
return create(null, includePathDeserializer, includeResponseDeserializer);
}
public static ObjectMapper createYaml() {
return createYaml(true, true);
}
protected static ObjectMapper createYaml(boolean includePathDeserializer, boolean includeResponseDeserializer) {
return create(new YAMLFactory(), includePathDeserializer, includeResponseDeserializer);
}
private static ObjectMapper create(JsonFactory jsonFactory, boolean includePathDeserializer, boolean includeResponseDeserializer) {
ObjectMapper mapper = jsonFactory == null ? new ObjectMapper() : new ObjectMapper(jsonFactory);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return mapper;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy