com.fasterxml.jackson.databind.deser.BeanDeserializerModifier源码实例Demo

类com.fasterxml.jackson.databind.deser.BeanDeserializerModifier源码实例Demo

下面列出了com.fasterxml.jackson.databind.deser.BeanDeserializerModifier 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: vividus   文件: ObjectMapperFactory.java
public static ObjectMapper createWithCaseInsensitiveEnumDeserializer()
{
    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new BeanDeserializerModifier()
    {
        @Override
        public JsonDeserializer<Enum<?>> modifyEnumDeserializer(DeserializationConfig config, final JavaType type,
                BeanDescription beanDescription, final JsonDeserializer<?> deserializer)
        {
            return new JsonDeserializer<>()
            {
                @SuppressWarnings({ "unchecked", "rawtypes" })
                @Override
                public Enum<?> deserialize(JsonParser parser, DeserializationContext context) throws IOException
                {
                    return Enum.valueOf((Class<? extends Enum>) type.getRawClass(),
                            parser.getValueAsString().toUpperCase());
                }
            };
        }
    });
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(module);
    return objectMapper;
}
 
源代码2 项目: client-sdk-java   文件: ObjectMapperFactory.java
private static ObjectMapper configureObjectMapper(
        ObjectMapper objectMapper, boolean shouldIncludeRawResponses) {
    if (shouldIncludeRawResponses) {
        SimpleModule module = new SimpleModule();
        module.setDeserializerModifier(new BeanDeserializerModifier() {
            @Override
            public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config,
                                                          BeanDescription beanDesc,
                                                          JsonDeserializer<?> deserializer) {
                if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) {
                    return new RawResponseDeserializer(deserializer);
                }

                return deserializer;
            }
        });

        objectMapper.registerModule(module);
    }

    objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    return objectMapper;
}
 
源代码3 项目: etherscan-explorer   文件: ObjectMapperFactory.java
private static ObjectMapper configureObjectMapper(
        ObjectMapper objectMapper, boolean shouldIncludeRawResponses) {
    if (shouldIncludeRawResponses) {
        SimpleModule module = new SimpleModule();
        module.setDeserializerModifier(new BeanDeserializerModifier() {
            @Override
            public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config,
                                                          BeanDescription beanDesc,
                                                          JsonDeserializer<?> deserializer) {
                if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) {
                    return new RawResponseDeserializer(deserializer);
                }

                return deserializer;
            }
        });

        objectMapper.registerModule(module);
    }

    objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    return objectMapper;
}
 
源代码4 项目: openapi-generator   文件: GenerateBatch.java
static SimpleModule getCustomDeserializationModel(final File includesDir) {
    // Create a module which loads our config files, but supports a special "!include" key which can point to an existing config file.
    // This allows us to create a sort of meta-config which holds configs which are otherwise required at CLI time (via generate task).
    // That is, this allows us to create a wrapper config for generatorName, inputSpec, outputDir, etc.
    SimpleModule module = new SimpleModule("GenerateBatch");
    module.setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config,
                                                      BeanDescription bd, JsonDeserializer<?> original) {
            JsonDeserializer<?> result;
            if (bd.getBeanClass() == DynamicSettings.class) {
                result = new DynamicSettingsRefSupport(original, includesDir);
            } else {
                result = original;
            }
            return result;
        }
    });

    return module;
}
 
源代码5 项目: botbuilder-java   文件: FlatteningDeserializer.java
/**
 * Gets a module wrapping this serializer as an adapter for the Jackson
 * ObjectMapper.
 *
 * @param mapper the object mapper for default deserializations
 * @return a simple module to be plugged onto Jackson ObjectMapper.
 */
public static SimpleModule getModule(final ObjectMapper mapper) {
    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
            if (BeanDeserializer.class.isAssignableFrom(deserializer.getClass())) {
                // Apply flattening deserializer on all POJO types.
                return new FlatteningDeserializer(beanDesc.getBeanClass(), deserializer, mapper);
            } else {
                return deserializer;
            }
        }
    });
    return module;
}
 
/**
 * Gets a module wrapping this serializer as an adapter for the Jackson
 * ObjectMapper.
 *
 * @param mapper the object mapper for default deserializations
 * @return a simple module to be plugged onto Jackson ObjectMapper.
 */
public static SimpleModule getModule(final ObjectMapper mapper) {
    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
            for (Class<?> c : TypeToken.of(beanDesc.getBeanClass()).getTypes().classes().rawTypes()) {
                Field[] fields = c.getDeclaredFields();
                for (Field field : fields) {
                    if ("additionalProperties".equalsIgnoreCase(field.getName())) {
                        JsonProperty property = field.getAnnotation(JsonProperty.class);
                        if (property != null && property.value().isEmpty()) {
                            return new AdditionalPropertiesDeserializer(beanDesc.getBeanClass(), deserializer, mapper);
                        }
                    }
                }
            }
            return deserializer;
        }
    });
    return module;
}
 
源代码7 项目: allure2   文件: XmlParserModule.java
@Override
public void setupModule(final SetupContext context) {
    super.setupModule(context);
    context.addBeanDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<?> modifyCollectionDeserializer(final DeserializationConfig config,
                                                                final CollectionType type,
                                                                final BeanDescription beanDesc,
                                                                final JsonDeserializer<?> deserializer) {
            if (deserializer instanceof CollectionDeserializer) {
                return new ListDeserializer((CollectionDeserializer) deserializer);
            } else {
                return super.modifyCollectionDeserializer(config, type, beanDesc,
                        deserializer);
            }
        }
    });
}
 
/**
 * Gets a module wrapping this serializer as an adapter for the Jackson
 * ObjectMapper.
 *
 * @param mapper the object mapper for default deserializations
 * @return a simple module to be plugged onto Jackson ObjectMapper.
 */
public static SimpleModule getModule(final ObjectMapper mapper) {
    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
            if (BeanDeserializer.class.isAssignableFrom(deserializer.getClass())) {
                // Apply flattening deserializer on all POJO types.
                return new FlatteningDeserializer(beanDesc.getBeanClass(), deserializer, mapper);
            } else {
                return deserializer;
            }
        }
    });
    return module;
}
 
/**
 * Gets a module wrapping this serializer as an adapter for the Jackson
 * ObjectMapper.
 *
 * @param mapper the object mapper for default deserializations
 * @return a simple module to be plugged onto Jackson ObjectMapper.
 */
public static SimpleModule getModule(final ObjectMapper mapper) {
    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
            for (Class<?> c : TypeToken.of(beanDesc.getBeanClass()).getTypes().classes().rawTypes()) {
                Field[] fields = c.getDeclaredFields();
                for (Field field : fields) {
                    if ("additionalProperties".equalsIgnoreCase(field.getName())) {
                        JsonProperty property = field.getAnnotation(JsonProperty.class);
                        if (property != null && property.value().isEmpty()) {
                            return new AdditionalPropertiesDeserializer(beanDesc.getBeanClass(), deserializer, mapper);
                        }
                    }
                }
            }
            return deserializer;
        }
    });
    return module;
}
 
源代码10 项目: gravitee-gateway   文件: StandaloneConfiguration.java
@Bean
public ObjectMapper objectMapper() {
    ObjectMapper mapper = new GraviteeMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config,
                                                             final JavaType type,
                                                             BeanDescription beanDesc,
                                                             final JsonDeserializer<?> deserializer) {
            return new JsonDeserializer<Enum>() {
                @Override
                public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
                    Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
                    return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase());
                }
            };
        }
    });

    mapper.registerModule(module);

    return mapper;
}
 
源代码11 项目: Flink-CEPplus   文件: AWSUtil.java
/**
 * 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);
	}
}
 
源代码12 项目: flink   文件: AWSUtil.java
/**
 * 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);
	}
}
 
源代码13 项目: n2o-framework   文件: RestEngineTimeModule.java
public RestEngineTimeModule(String[] patterns) {
    this();
    setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
            if (beanDesc.getBeanClass() == String.class) {
                CustomDateDeserializer dateDeserializer = new CustomDateDeserializer(deserializer);
                dateDeserializer.setPatterns(patterns);
                return dateDeserializer;
            }
            return deserializer;
        }
    });
}
 
源代码14 项目: n2o-framework   文件: RestEngineTimeModule.java
public RestEngineTimeModule(String[] patterns, String[] exclusionKeys) {
    this();
    setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
            if (beanDesc.getBeanClass() == String.class) {
                CustomDateDeserializer dateDeserializer = new CustomDateDeserializer(deserializer);
                dateDeserializer.setPatterns(patterns);
                dateDeserializer.setExclusions(exclusionKeys);
                return dateDeserializer;
            }
            return deserializer;
        }
    });
}
 
源代码15 项目: web3sdk   文件: ObjectMapperFactory.java
private static ObjectMapper configureObjectMapper(
        ObjectMapper objectMapper, boolean shouldIncludeRawResponses) {
    if (shouldIncludeRawResponses) {
        SimpleModule module = new SimpleModule();
        module.setDeserializerModifier(
                new BeanDeserializerModifier() {
                    @Override
                    public JsonDeserializer<?> modifyDeserializer(
                            DeserializationConfig config,
                            BeanDescription beanDesc,
                            JsonDeserializer<?> deserializer) {
                        if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) {
                            return new RawResponseDeserializer(deserializer);
                        }

                        return deserializer;
                    }
                });

        objectMapper.registerModule(module);
    }

    objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    return objectMapper;
}
 
源代码16 项目: web3j   文件: ObjectMapperFactory.java
private static ObjectMapper configureObjectMapper(
        ObjectMapper objectMapper, boolean shouldIncludeRawResponses) {
    if (shouldIncludeRawResponses) {
        SimpleModule module = new SimpleModule();
        module.setDeserializerModifier(
                new BeanDeserializerModifier() {
                    @Override
                    public JsonDeserializer<?> modifyDeserializer(
                            DeserializationConfig config,
                            BeanDescription beanDesc,
                            JsonDeserializer<?> deserializer) {
                        if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) {
                            return new RawResponseDeserializer(deserializer);
                        }

                        return deserializer;
                    }
                });

        objectMapper.registerModule(module);
    }

    objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    return objectMapper;
}
 
源代码17 项目: JglTF   文件: JacksonUtils.java
/**
 * Creates a BeanDeserializerModifier that replaces the 
 * SettableBeanProperties in the BeanDeserializerBuilder with
 * ErrorReportingSettableBeanProperty instances that forward
 * information about errors when setting bean properties to the
 * given consumer. (Don't ask ... )  
 * 
 * @param jsonErrorConsumer The consumer for {@link JsonError}s.
 * If this is <code>null</code>, then no errors will be reported.
 * @return The modifier
 */
private static BeanDeserializerModifier 
    createErrorHandlingBeanDeserializerModifier(
        Consumer<? super JsonError> jsonErrorConsumer)
{
    return new BeanDeserializerModifier()
    {
        @Override
        public BeanDeserializerBuilder updateBuilder(
            DeserializationConfig config,
            BeanDescription beanDesc,
            BeanDeserializerBuilder builder)
        {
            Iterator<SettableBeanProperty> propertiesIterator =
                builder.getProperties();
            while (propertiesIterator.hasNext())
            {
                SettableBeanProperty property = propertiesIterator.next();
                SettableBeanProperty wrappedProperty =
                    new ErrorReportingSettableBeanProperty(
                        property, jsonErrorConsumer);
                builder.addOrReplaceProperty(wrappedProperty, true);
            }
            return builder;
        }
    };    
}
 
public ObjectMapperResolver() {
    mapper = new GraviteeMapper();

    //because Permissions are represented as char[]
    mapper.enable(SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS);

    // register filter provider
    registerFilterProvider();

    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config,
                                                             final JavaType type,
                                                             BeanDescription beanDesc,
                                                             final JsonDeserializer<?> deserializer) {
            return new JsonDeserializer<Enum>() {
                @Override
                public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
                    Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
                    return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase());
                }
            };
        }
    });
    module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) {
        @Override
        public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
            jgen.writeString(value.name().toLowerCase());
        }
    });
    mapper.registerModule(module);
}
 
public ObjectMapperResolver() {
    mapper = new GraviteeMapper();

    //because Permissions are represented as char[]
    mapper.enable(SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS);

    // register filter provider
    registerFilterProvider();

    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config,
                                                             final JavaType type,
                                                             BeanDescription beanDesc,
                                                             final JsonDeserializer<?> deserializer) {
            return new JsonDeserializer<Enum>() {
                @Override
                public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
                    Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
                    return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase());
                }
            };
        }
    });
    module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) {
        @Override
        public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
            jgen.writeString(value.name().toLowerCase());
        }
    });
    mapper.registerModule(module);
    
    mapper.registerModule(new JavaTimeModule());
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
 
/**
 * Register Jackson module that maps enums as lowercase. Per http://stackoverflow.com/a/24173645.
 */
@SuppressWarnings("rawtypes")
private static void registerEnumModule(ObjectMapper mapper) {
    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config,
                                                             final JavaType type,
                                                             BeanDescription beanDesc,
                                                             final JsonDeserializer<?> deserializer) {
            return new JsonDeserializer<Enum>() {
                @Override
                public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
                    @SuppressWarnings("unchecked") Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
                    return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase());
                }
            };
        }
    });
    module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) {
        @Override
        public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
            jgen.writeString(value.name().toLowerCase());
        }
    });
    mapper.registerModule(module);
}
 
源代码21 项目: flink   文件: AWSUtil.java
/**
 * 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);
	}
}
 
源代码22 项目: lams   文件: SimpleModule.java
/**
 * @since 2.2
 */
public SimpleModule setDeserializerModifier(BeanDeserializerModifier mod) {
    _deserializerModifier = mod;
    return this;
}
 
public ObjectMapperResolver() {
    mapper = new ObjectMapper();

    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config,
                                                             final JavaType type,
                                                             BeanDescription beanDesc,
                                                             final JsonDeserializer<?> deserializer) {
            return new JsonDeserializer<Enum>() {
                @Override
                public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
                    Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
                    return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase());
                }
            };
        }
    });
    module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) {
        @Override
        public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
            jgen.writeString(value.name().toLowerCase());
        }
    });
    module.addSerializer(Instant.class, new StdSerializer<Instant>(Instant.class) {
        @Override
        public void serialize(Instant instant, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
            jsonGenerator.writeNumber(instant.toEpochMilli());
        }
    });
    module.addDeserializer(JWK.class, new StdDeserializer<JWK>(JWK.class) {
        @Override
        public JWK deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
            JsonNode node = jsonParser.getCodec().readTree(jsonParser);
            String kty = node.get("kty").asText();
            if (kty == null) {
                return null;
            }
            JWK jwk = null;
            switch (kty) {
                case "RSA":
                    jwk = jsonParser.getCodec().treeToValue(node, RSAKey.class);
                    break;
                case "EC":
                    jwk = jsonParser.getCodec().treeToValue(node, ECKey.class);
                    break;
                case "oct":
                    jwk = jsonParser.getCodec().treeToValue(node, OCTKey.class);
                    break;
                case "OKP":
                    jwk = jsonParser.getCodec().treeToValue(node, OKPKey.class);
                    break;
            }
            return jwk;
        }
    });
    mapper.addMixIn(Domain.class, MixIn.class);
    mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.registerModule(module);
    mapper.registerModule(new Jdk8Module());
    mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
}
 
源代码24 项目: Sparkplug   文件: DeserializerModule.java
public DeserializerModule(BeanDeserializerModifier deserializerModifier) {
    super("DeserializerModule", Version.unknownVersion());
    this.deserializerModifier = deserializerModifier;
}
 
源代码25 项目: logsniffer   文件: BeanConfigFactoryManager.java
@SuppressWarnings("unchecked")
@PostConstruct
private void initJsonMapper() {
	final SimpleModule module = new SimpleModule();
	module.setDeserializerModifier(new BeanDeserializerModifier() {
		@Override
		public JsonDeserializer<?> modifyDeserializer(final DeserializationConfig config,
				final BeanDescription beanDesc, final JsonDeserializer<?> deserializer) {
			if (ConfiguredBean.class.isAssignableFrom(beanDesc.getBeanClass())) {
				return new ConfiguredBeanDeserializer(deserializer);
			}
			return deserializer;
		}
	});
	jsonMapper.registerModule(module);
	if (postConstructors != null) {
		for (final BeanPostConstructor<?> bpc : postConstructors) {
			mappedPostConstrucors.put(bpc.getClass(), bpc);
		}
	}

	// Register sub beans
	final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
			false);
	final AssignableTypeFilter filter4configBenas = new AssignableTypeFilter(ConfiguredBean.class);
	scanner.addIncludeFilter(filter4configBenas);

	for (final BeanDefinition bd : scanner.findCandidateComponents("com.logsniffer")) {
		try {
			final Class<? extends ConfiguredBean> clazz = (Class<? extends ConfiguredBean>) Class
					.forName(bd.getBeanClassName());
			final JsonTypeName jsonNameAnnotation = clazz.getAnnotation(JsonTypeName.class);
			final List<String> names = new ArrayList<String>();
			configBeanNames.put(clazz, names);
			if (jsonNameAnnotation != null) {
				names.add(jsonNameAnnotation.value());
				if (jsonNameAnnotation.deprecated() != null) {
					for (final String dep : jsonNameAnnotation.deprecated()) {
						names.add(dep);
					}
				}
			}
			names.add(clazz.getSimpleName());
			logger.debug("Registered JSON type {} for following names: {}", clazz, names);
		} catch (final ClassNotFoundException e) {
			logger.warn("Failed to register JSON type name for " + bd.getBeanClassName(), e);
		}
	}
}
 
源代码26 项目: lams   文件: Module.java
/**
 * Method that module can use to register additional modifier objects to
 * customize configuration and construction of bean deserializers.
 * 
 * @param mod Modifier to register
 */
public void addBeanDeserializerModifier(BeanDeserializerModifier mod);
 
源代码评论
动弹
沙发等你来抢
 类方法
 同包方法