Java Code Examples for com.fasterxml.jackson.databind.ObjectMapper#addHandler()

The following examples show how to use com.fasterxml.jackson.databind.ObjectMapper#addHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PersistenceManager.java    From milkman with MIT License 5 votes vote down vote up
@PostConstruct
public void init() {
	JacksonMapper nitriteMapper = new JacksonMapper();
	ObjectMapper mapper = nitriteMapper.getObjectMapper();
	mapper.addHandler(new UnknownPluginHandler());
	db = CompletableFuture.supplyAsync(() -> createOrOpenDb(nitriteMapper));
}
 
Example 2
Source File: GoogleSearchProviderImpl.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private GoogleGroupIndex readGoogleGroupIndex(final String group, final String url, int connectTimeout, int readTimeout) {
    try {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
        setTimeout(restTemplate, connectTimeout, readTimeout);
        ObjectMapper mapper = Jackson2ObjectMapperBuilder.xml().build();
        mapper = mapper.addHandler(new DeserializationProblemHandler() {
            @Override
            public boolean handleUnknownProperty(DeserializationContext ctxt, JsonParser p, JsonDeserializer<?> deserializer, Object beanOrClass, String propertyName) throws IOException {
                if (beanOrClass instanceof GoogleGroupIndex) {
                    if ("versions".equals(propertyName)) {
                        if (((GoogleGroupIndex) beanOrClass).lastArtifactId != null) {
                            ((GoogleGroupIndex) beanOrClass).downloaded.put(((GoogleGroupIndex) beanOrClass).lastArtifactId, p.getText());
                            ((GoogleGroupIndex) beanOrClass).lastArtifactId = null;
                        }
                    } else {
                        ((GoogleGroupIndex) beanOrClass).lastArtifactId = propertyName;
                    }
                    return true;
                }
                return false;
            }

        });
        restTemplate.getMessageConverters().clear();
        restTemplate.getMessageConverters().add(new MappingJackson2XmlHttpMessageConverter(mapper));
        ResponseEntity<GoogleGroupIndex> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(requestHeaders), GoogleGroupIndex.class);
        GoogleGroupIndex groupIndex = response.getBody();
        groupIndex.group = group;
        groupIndex.url = url;
        return groupIndex.build();
    } catch (Exception exception) {
        Exceptions.printStackTrace(exception);
    }
    return null;
}
 
Example 3
Source File: GoogleSearchProviderImpl.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private GoogleMasterIndex readGoogleMasterIndex(int connectTimeout, int readTimeout) {
    try {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
        setTimeout(restTemplate, connectTimeout, readTimeout);
        ObjectMapper mapper = Jackson2ObjectMapperBuilder.xml().build();
        mapper = mapper.addHandler(new DeserializationProblemHandler() {
            @Override
            public boolean handleUnknownProperty(DeserializationContext ctxt, JsonParser p, JsonDeserializer<?> deserializer, Object beanOrClass, String propertyName) throws IOException {
                if (beanOrClass instanceof GoogleMasterIndex) {
                    ((GoogleMasterIndex) beanOrClass).getGroups().put(propertyName, BASE_URL + propertyName.replace(".", "/") + "/" + GROUP_INDEX);
                    return true;
                }
                return false;
            }

        });
        restTemplate.getMessageConverters().clear();
        restTemplate.getMessageConverters().add(new MappingJackson2XmlHttpMessageConverter(mapper));
        ResponseEntity<GoogleMasterIndex> response = restTemplate.exchange(BASE_URL + MASTER_INDEX, HttpMethod.GET, new HttpEntity<>(requestHeaders), GoogleMasterIndex.class);
        return response.getBody();
    } catch (Exception exception) {
        Exceptions.printStackTrace(exception);
    }
    return null;
}
 
Example 4
Source File: JacksonUtils.java    From JglTF with MIT License 5 votes vote down vote up
/**
 * Perform a default configuration of the given object mapper for
 * parsing glTF data
 * 
 * @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.
 */
public 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));
        }
    });

}
 
Example 5
Source File: RestJsonConverter.java    From sdk-rest with MIT License 5 votes vote down vote up
/**
 * Creates the ObjectMapper that serializes json to entity. Wraps the root (most often "data").
 * 
 * See @JsonRootName on the RestEntities
 * 
 * @return
 */
private ObjectMapper createObjectMapperWithRootUnWrap() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
    mapper.addHandler(new CustomDeserializationProblemHandler());
   
    
    mapper.registerModule(new JodaModule());
    return mapper;
}
 
Example 6
Source File: DnDCellFactory.java    From milkman with MIT License 4 votes vote down vote up
private ObjectMapper createMapper() {
	ObjectMapper mapper = new ObjectMapper();
	mapper.addHandler(new UnknownPluginHandler());
	return mapper;
}
 
Example 7
Source File: GitWorkspaceSync.java    From milkman with MIT License 4 votes vote down vote up
private ObjectMapper createMapper() {
	ObjectMapper mapper = new ObjectMapper();
	mapper.addHandler(new UnknownPluginHandler());
	mapper.enable(SerializationFeature.INDENT_OUTPUT); //allows git line-by-line diffs
	return mapper;
}
 
Example 8
Source File: PrivateBinImporter.java    From milkman with MIT License 4 votes vote down vote up
private ObjectMapper createMapper() {
	ObjectMapper mapper = new ObjectMapper();
	mapper.addHandler(new UnknownPluginHandler());
	return mapper;
}
 
Example 9
Source File: PrivateBinWorkspaceExporter.java    From milkman with MIT License 4 votes vote down vote up
private ObjectMapper createMapper() {
	ObjectMapper mapper = new ObjectMapper();
	mapper.addHandler(new UnknownPluginHandler());
	return mapper;
}
 
Example 10
Source File: PrivateBinExporter.java    From milkman with MIT License 4 votes vote down vote up
private ObjectMapper createMapper() {
	ObjectMapper mapper = new ObjectMapper();
	mapper.addHandler(new UnknownPluginHandler());
	return mapper;
}
 
Example 11
Source File: PrivateBinCollectionExporter.java    From milkman with MIT License 4 votes vote down vote up
private ObjectMapper createMapper() {
	ObjectMapper mapper = new ObjectMapper();
	mapper.addHandler(new UnknownPluginHandler());
	return mapper;
}