当前位置: 首页>>代码示例>>Java>>正文


Java SimpleModule.setDeserializerModifier方法代码示例

本文整理汇总了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;
}
 
开发者ID:numsg,项目名称:spring-boot-seed,代码行数:28,代码来源:JsonUtil.java

示例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
	}
 
开发者ID:heindorf,项目名称:cikm16-wdvd-feature-extraction,代码行数:18,代码来源:JsonNormalizerTest.java

示例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;
}
 
开发者ID:cslee00,项目名称:datadog-jmx-collector,代码行数:25,代码来源:JmxCollectorMain.java

示例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;
}
 
开发者ID:maenu,项目名称:kowalski,代码行数:14,代码来源:Factory.java

示例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;
}
 
开发者ID:web3j,项目名称:web3j,代码行数:26,代码来源:ObjectMapperFactory.java

示例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);
}
 
开发者ID:gravitee-io,项目名称:graviteeio-access-management,代码行数:29,代码来源:ObjectMapperResolver.java

示例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;
}
 
开发者ID:Azure,项目名称:autorest-clientruntime-for-java,代码行数:21,代码来源:FlatteningDeserializer.java

示例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;
}
 
开发者ID:orshachar,项目名称:known-issue,代码行数:7,代码来源:JacksonEnumExtension.java


注:本文中的com.fasterxml.jackson.databind.module.SimpleModule.setDeserializerModifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。