當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。