org.iris_events.asyncapi.runtime.json.IrisObjectMapper Maven / Gradle / Ivy
package org.iris_events.asyncapi.runtime.json;
import org.iris_events.asyncapi.runtime.io.MixinResolver;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
public class IrisObjectMapper {
private static final ObjectMapper MAPPER = new ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.setMixInResolver(new MixinResolver())
.setVisibility(new ObjectMapper().getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
public static final ObjectMapper MAPPER_YAML;
static {
YAMLFactory factory = new YAMLFactory();
factory.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES);
factory.enable(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS);
MAPPER_YAML = new ObjectMapper(factory)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.setMixInResolver(new MixinResolver())
.setVisibility(new ObjectMapper().getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
}
public static ObjectMapper getObjectMapper() {
return MAPPER;
}
public static ObjectMapper getYamlObjectMapper() {
return MAPPER_YAML;
}
}