com.jslsolucoes.jax.rs.provider.se.ObjectMapperCreator Maven / Gradle / Ivy
package com.jslsolucoes.jax.rs.provider.se;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
public class ObjectMapperCreator {
private Class>[] mixIns;
public static ObjectMapperCreator newCreator() {
return new ObjectMapperCreator();
}
public ObjectMapperCreator withMixIns(Class>... mixIns) {
this.mixIns = mixIns;
return this;
}
@Produces
@ApplicationScoped
public ObjectMapper wrap() {
return new ObjectMapper(build(Object.class, JsonExcludeMixIn.class));
}
public com.fasterxml.jackson.databind.ObjectMapper build() {
return build(mixIns);
}
public com.fasterxml.jackson.databind.ObjectMapper build(Class>... mixIns) {
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
objectMapper.setSerializationInclusion(Include.NON_EMPTY);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.registerModule(new JavaTimeModule());
if (mixIns != null) {
objectMapper.addMixIn(mixIns[0], mixIns[1]);
}
return objectMapper;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy