Search in sources :

Example 1 with DeserializerFactory

use of com.fasterxml.jackson.databind.deser.DeserializerFactory in project flink by apache.

the class AWSUtil method setAwsClientConfigProperties.

/**
 * Set all prefixed properties on {@link ClientConfiguration}.
 *
 * @param config
 * @param configProps
 */
public static void setAwsClientConfigProperties(ClientConfiguration config, Properties configProps) {
    Map<String, Object> awsConfigProperties = new HashMap<>();
    for (Map.Entry<Object, Object> entry : configProps.entrySet()) {
        String key = (String) entry.getKey();
        if (key.startsWith(AWS_CLIENT_CONFIG_PREFIX)) {
            awsConfigProperties.put(key.substring(AWS_CLIENT_CONFIG_PREFIX.length()), entry.getValue());
        }
    }
    // Jackson does not like the following properties
    String[] ignorableProperties = { "secureRandom" };
    BeanDeserializerModifier modifier = new BeanDeserializerModifierForIgnorables(ClientConfiguration.class, ignorableProperties);
    DeserializerFactory factory = BeanDeserializerFactory.instance.withDeserializerModifier(modifier);
    ObjectMapper mapper = new ObjectMapper(null, null, new DefaultDeserializationContext.Impl(factory));
    JsonNode propTree = mapper.convertValue(awsConfigProperties, JsonNode.class);
    try {
        mapper.readerForUpdating(config).readValue(propTree);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : BeanDeserializerModifier(com.fasterxml.jackson.databind.deser.BeanDeserializerModifier) DefaultDeserializationContext(com.fasterxml.jackson.databind.deser.DefaultDeserializationContext) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) BeanDeserializerFactory(com.fasterxml.jackson.databind.deser.BeanDeserializerFactory) DeserializerFactory(com.fasterxml.jackson.databind.deser.DeserializerFactory) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BeanDeserializerFactory (com.fasterxml.jackson.databind.deser.BeanDeserializerFactory)1 BeanDeserializerModifier (com.fasterxml.jackson.databind.deser.BeanDeserializerModifier)1 DefaultDeserializationContext (com.fasterxml.jackson.databind.deser.DefaultDeserializationContext)1 DeserializerFactory (com.fasterxml.jackson.databind.deser.DeserializerFactory)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1