List of usage examples for com.fasterxml.jackson.databind ObjectMapper addHandler
public ObjectMapper addHandler(DeserializationProblemHandler h)
From source file:de.javagl.jgltf.model.io.JacksonUtils.java
/** * Perform a default configuration of the given object mapper for * parsing glTF data/*from w ww . ja va2 s. c o m*/ * * @param objectMapper The object mapper * @param jsonErrorConsumer The consumer for {@link JsonError}s. If this * is <code>null</code>, then the errors will not be handled. * <code>null</code>, then log outputs will be created for the errors */ static void configure(ObjectMapper objectMapper, Consumer<? super JsonError> jsonErrorConsumer) { // Some glTF files have single values instead of arrays, // so accept this for compatibility reasons objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.addHandler(createDeserializationProblemHandler(jsonErrorConsumer)); // Register the module that will initialize the setup context // with the error handling bean deserializer modifier objectMapper.registerModule(new SimpleModule() { /** * Serial UID */ private static final long serialVersionUID = 1L; @Override public void setupModule(SetupContext context) { super.setupModule(context); context.addBeanDeserializerModifier(createErrorHandlingBeanDeserializerModifier(jsonErrorConsumer)); } }); }
From source file:org.jberet.support.io.MappingJsonFactoryObjectFactory.java
static void configureDeserializationProblemHandlers(final ObjectMapper objectMapper, final String deserializationProblemHandlers, final ClassLoader classLoader) throws Exception { final StringTokenizer st = new StringTokenizer(deserializationProblemHandlers, ", "); while (st.hasMoreTokens()) { final Class<?> c = classLoader.loadClass(st.nextToken()); objectMapper.addHandler((DeserializationProblemHandler) c.newInstance()); }//ww w . j a va 2 s. c o m }
From source file:org.bonitasoft.web.designer.config.DesignerConfig.java
@Bean public ObjectMapper objectMapper() { ObjectMapper objectMapper = new ObjectMapper(); //By default all properties without explicit view definition are included in serialization. //To use JsonView we have to change this parameter objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false); //We don't have to serialize null values objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.registerModule(new JodaModule()); objectMapper.registerSubtypes(jacksonSubTypes()); //add Handler to migrate old json objectMapper.addHandler(new JacksonDeserializationProblemHandler()); return objectMapper; }