本文整理汇总了Java中com.fasterxml.jackson.databind.module.SimpleModule.setDeserializerModifier方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleModule.setDeserializerModifier方法的具体用法?Java SimpleModule.setDeserializerModifier怎么用?Java SimpleModule.setDeserializerModifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.module.SimpleModule
的用法示例。
在下文中一共展示了SimpleModule.setDeserializerModifier方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEnumSimpleModule
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
/**
* 获取ObjectMapper反序列化枚举使用的module
* 支持忽略大小写
* @return
*/
public static SimpleModule getEnumSimpleModule() {
//枚举转换,支持忽略大小写的匹配
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 rawClass = type.getRawClass();
return getEnum(jp.getValueAsString(), rawClass);
}
};
}
});
return module;
}
示例2: testWDTKParsing
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
private void testWDTKParsing(String filename) throws IOException {
String jsonString = readFile(filename, StandardCharsets.UTF_8);
SimpleModule module = new SimpleModule();
module.setDeserializerModifier(new MapDeserializerModifier());
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
// JsonNode root = mapper.readTree(jsonString);
// mapper.readValue(mapper.treeAsTokens(root), JacksonItemDocument.class);
JacksonItemDocument itemDocument =
mapper.readValue(jsonString, JacksonItemDocument.class);
itemDocument.setSiteIri(Datamodel.SITE_WIKIDATA);
itemDocument.toString(); // raises an exception if information is missing
}
示例3: objectMapper
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
@Bean
public ObjectMapper objectMapper() {
ObjectMapper 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.addDeserializer( Expression.class, new ExpressionDeserializer( expressionParser() ) );
module.addDeserializer( Range.class, new RangeDeserializer() );
mapper.registerModule( module );
return mapper;
}
示例4: newObjectMapper
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
public ObjectMapper newObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addDeserializer(Artifact.class, new ArtifactDeserializer());
module.addDeserializer(SolrQuery.class, new SolrQueryDeserializer());
module.addDeserializer(Page.class, new PageDeserializer(objectMapper));
module.addSerializer(Artifact.class, new ArtifactSerializer());
module.addSerializer(SolrQuery.class, new SolrQuerySerializer());
module.addSerializer(Page.class, new PageSerializer());
module.setDeserializerModifier(new ArtifactDeserializerModifier());
objectMapper.registerModule(module);
return objectMapper;
}
示例5: configureObjectMapper
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
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;
}
示例6: ObjectMapperResolver
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
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());
}
});
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.registerModule(module);
}
示例7: getModule
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
/**
* 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 (beanDesc.getBeanClass().getAnnotation(JsonFlatten.class) != null) {
return new FlatteningDeserializer(beanDesc.getBeanClass(), deserializer, mapper);
}
return deserializer;
}
});
return module;
}
示例8: createModule
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
public static SimpleModule createModule() {
final SimpleModule module = new SimpleModule();
module.setDeserializerModifier(new EnumBeanDeserializerModifier());
module.addSerializer(Enum.class, new EnumBeanSerializer(Enum.class));
return module;
}