本文整理匯總了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;
}