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


Java SimpleModule.addDeserializer方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.module.SimpleModule.addDeserializer方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleModule.addDeserializer方法的具体用法?Java SimpleModule.addDeserializer怎么用?Java SimpleModule.addDeserializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.module.SimpleModule的用法示例。


在下文中一共展示了SimpleModule.addDeserializer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: JacksonObjectMapperConfig

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
public JacksonObjectMapperConfig() {
	super();
	
	this.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);		
	//this.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); 不增加,避免key值为null,而避免节点消失
	this.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	this.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true); 
	
	//this.setSerializationInclusion(Include.NON_EMPTY); //对象转字符串时,只转化非空字段 zjs 需要占位
	
	//SimpleModule module = new SimpleModule();
       SimpleModule module = new SimpleModule("HTML XSS Serializer",
               new Version(1, 0, 0, "FINAL", "com.simbest", "ep-jsonmodule"));
       module.addSerializer(new JsonHtmlXssSerializer(String.class));
       module.addDeserializer(Date.class, new CustomJsonDateDeseralizer());
       // Add more here ...
       registerModule(module);
}
 
开发者ID:simbest,项目名称:simbest-cores,代码行数:19,代码来源:JacksonObjectMapperConfig.java

示例2: setUp

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
@Before public void setUp() {
  SimpleModule module = new SimpleModule();
  module.addSerializer(AnInterface.class, new AnInterfaceSerializer());
  module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer());
  ObjectMapper mapper = new ObjectMapper();
  mapper.registerModule(module);
  mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
  mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
  mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
  mapper.setVisibilityChecker(mapper.getSerializationConfig()
      .getDefaultVisibilityChecker()
      .withFieldVisibility(JsonAutoDetect.Visibility.ANY));

  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl(server.url("/"))
      .addConverterFactory(JacksonConverterFactory.create(mapper))
      .build();
  service = retrofit.create(Service.class);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:JacksonConverterFactoryTest.java

示例3: read

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
public static SecurityAnalysisResult read(Path jsonFile) {
    Objects.requireNonNull(jsonFile);

    try (InputStream is = Files.newInputStream(jsonFile)) {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);

        SimpleModule module = new SimpleModule();
        module.addDeserializer(SecurityAnalysisResult.class, new SecurityAnalysisResultDeserializer());
        module.addDeserializer(NetworkMetadata.class, new NetworkMetadataDeserializer());
        module.addDeserializer(PostContingencyResult.class, new PostContingencyResultDeserializer());
        module.addDeserializer(LimitViolationsResult.class, new LimitViolationResultDeserializer());
        module.addDeserializer(LimitViolation.class, new LimitViolationDeserializer());
        module.addDeserializer(Contingency.class, new ContingencyDeserializer());
        module.addDeserializer(ContingencyElement.class, new ContingencyElementDeserializer());
        objectMapper.registerModule(module);

        return objectMapper.readValue(is, SecurityAnalysisResult.class);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:23,代码来源:SecurityAnalysisResultDeserializer.java

示例4: configObjectMapper

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
@Autowired
public void configObjectMapper(ObjectMapper objectMapper) {
    AggregationDeserializer deserializer = new AggregationDeserializer();
    deserializer.register("sterms", TermsAggregation.class);
    deserializer.register("histogram", HistogramAggregation.class);
    deserializer.register("date_histogram", DateHistogramAggregation.class);
    deserializer.register("avg", SingleValueMetricsAggregation.class);
    deserializer.register("sum", SingleValueMetricsAggregation.class);
    deserializer.register("max", SingleValueMetricsAggregation.class);
    deserializer.register("min", SingleValueMetricsAggregation.class);
    deserializer.register("cardinality", SingleValueMetricsAggregation.class);
    deserializer.register("value_count", SingleValueMetricsAggregation.class);


    SimpleModule module = new SimpleModule("AggregationDeserializer",
            new Version(1, 0, 0, null, "eu.luminis.elastic", "aggregation-elastic"));
    module.addDeserializer(Aggregation.class, deserializer);
    module.addKeyDeserializer(String.class, new AggregationKeyDeserializer());

    objectMapper.registerModule(module);
}
 
开发者ID:luminis-ams,项目名称:elastic-rest-spring-wrapper,代码行数:22,代码来源:RestClientConfig.java

示例5: newWrappingModule

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
private static <T1, T2> SimpleModule newWrappingModule(final Class<T1> wrapped, final Class<T2> wrapper, final Converter<T1, T2> converter) {
  SimpleModule module = new SimpleModule();
  module.addDeserializer(wrapper, new JsonDeserializer<T2>() {
    @Override
    public T2 deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
      return converter.convert(ctxt.readValue(p, wrapped));
    }
  });
  module.addSerializer(wrapper, new JsonSerializer<T2>() {
    @Override
    public void serialize(T2 value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
      serializers.defaultSerializeValue(converter.revert(value), gen);
    }
  });
  return module;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:JSONUtil.java

示例6: createMapper

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
public static ObjectMapper createMapper(KBId kbId) {
    ObjectMapper mapper = new ObjectMapper();
    SimpleModule module = new SimpleModule();
    module.addSerializer(Fact.class, new FactSerializer(kbId));
    module.addDeserializer(Fact.class, new FactDeSerializer(kbId));
    module.addSerializer(PropertyEntity.class, new PropertySerializer(kbId));
    module.addDeserializer(PropertyEntity.class, new PropertyDeserializer(kbId));
    module.addSerializer(InstanceEntity.class, new InstanceSerializer(kbId));
    module.addDeserializer(InstanceEntity.class, new InstanceDeserializer(kbId));
    module.addSerializer(ClassEntity.class, new ClassSerializer(kbId));
    mapper.registerModule(module);
    return mapper;
}
 
开发者ID:Lambda-3,项目名称:Stargraph,代码行数:14,代码来源:ObjectSerializer.java

示例7: createDefaultMapper

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
public static ObjectMapper createDefaultMapper() {

		final ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(Include.NON_NULL);
		mapper.configure(SerializationFeature.INDENT_OUTPUT, false);
		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

		SimpleModule module = new SimpleModule();
		module.addSerializer(Transaction.class, new TransactionSerializer());
		module.addDeserializer(Transaction.class, new TransactionDeserializer());
		module.addSerializer(Difficulty.class, new DifficultySerializer());
		module.addDeserializer(Difficulty.class, new DifficultyDeserializer());
		module.addSerializer(Block.class, new BlockSerializer());
		module.addDeserializer(Block.class, new BlockDeserializer());
		mapper.registerModule(module);

		return mapper;

	}
 
开发者ID:EonTechnology,项目名称:server,代码行数:21,代码来源:ObjectMapperProvider.java

示例8: loadHighscore

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
/**
* method that uses a Jackson mapper to read a json file and tun it into an arraylist of IPersonalScore objects
* @return an arraylist of IPersonalScore objects.
*/
   ArrayList loadHighscore() {
       ObjectMapper mapper = new ObjectMapper();
       SimpleModule module = new SimpleModule("ScoreSerializer", new Version(1, 0, 0, null, null, null));
       module.addDeserializer(DataPS.class, new ScoreDeserializer());
       mapper.registerModule(module);


       try {
           scoreList = mapper.readValue(new File("files/highscore.json"), new TypeReference<ArrayList<DataPS>>(){});
           
       } catch (IOException ex) {
           Logger.getLogger(DataHighscore.class.getName()).log(Level.SEVERE, null, ex);
       }
       return scoreList;
   }
 
开发者ID:jolluguy,项目名称:World-of-Zuul-SDU,代码行数:20,代码来源:DataHighscore.java

示例9: getDefaultObjectMapper

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
/**
 * Generates an {@link ObjectMapper} to serialize and deserialize JSON.
 *
 * @return The generated {@link ObjectMapper}.
 */
@Bean
public ObjectMapper getDefaultObjectMapper() {
	final ObjectMapper mapper = new ObjectMapper();

	final SimpleModule module = new SimpleModule("AnalysisSerializers", new Version(1, 0, 0, null, null, null));

	// Add custom serializer & deserializer for AnalyzerType so that we can retrieve the correct singleton instance from spring
	module.addSerializer(AnalyzerType.class, new AnalyzerTypeSerializer());
	module.addDeserializer(AnalyzerType.class, new AnalyzerTypeDeserializer());

	// Add custom serializer & deserializer for Analyzer so that we can save the parameter values used to create the analyzer
	module.addSerializer(Analyzer.class, new AnalyzerSerializer());
	module.addDeserializer(Analyzer.class, new AnalyzerDeserializer());
	mapper.registerModule(module);

	// Save type information in JSON when declared type is object so it is deserialized correctly
	// Used because AnalyzerSpec has a map of string to object for saved parameter values
	mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT);

	return mapper;
}
 
开发者ID:mizitch,项目名称:story-inspector,代码行数:27,代码来源:JsonMappingSpringConfig.java

示例10: getObjectMapper

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
public ObjectMapper getObjectMapper(){
    if(mapper==null){
        mapper=new ObjectMapper();
        mapper.configure(MapperFeature.USE_ANNOTATIONS, true);
        mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
        mapper.configure(JsonParser.Feature.IGNORE_UNDEFINED, true);
        mapper.configure(JsonParser.Feature.ALLOW_MISSING_VALUES, true);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setTimeZone(TimeZone.getDefault());
        SimpleModule module = new SimpleModule();
        module.addSerializer(DateTime.class,new DateTimeSerializer());
        module.addDeserializer(DateTime.class,new DateTimeDeserializer());
        mapper.registerModule(module);
    }
    return mapper;
}
 
开发者ID:SignalGo,项目名称:client-java,代码行数:17,代码来源:GoConvertorHelper.java

示例11: testGoalStateDeserializesNewValues

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
@Test
public void testGoalStateDeserializesNewValues() throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("valid-finished.yml").getFile());
    DefaultServiceSpec serviceSpec = DefaultServiceSpec.newGenerator(file, SCHEDULER_CONFIG).build();

    ObjectMapper objectMapper = SerializationUtils.registerDefaultModules(new ObjectMapper());
    DefaultServiceSpec.ConfigFactory.GoalStateDeserializer goalStateDeserializer =
            ((DefaultServiceSpec.ConfigFactory) serviceSpec.getConfigurationFactory(serviceSpec))
                    .getGoalStateDeserializer();

    SimpleModule module = new SimpleModule();
    module.addDeserializer(GoalState.class, goalStateDeserializer);
    objectMapper.registerModule(module);

    Assert.assertEquals(
            GoalState.FINISHED, SerializationUtils.fromString("\"ONCE\"", GoalState.class, objectMapper));
    Assert.assertEquals(
            GoalState.FINISHED, SerializationUtils.fromString("\"FINISHED\"", GoalState.class, objectMapper));
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:21,代码来源:DefaultServiceSpecTest.java

示例12: testGoalStateDeserializesOldValues

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
@Test
public void testGoalStateDeserializesOldValues() throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("valid-minimal.yml").getFile());
    DefaultServiceSpec serviceSpec = DefaultServiceSpec.newGenerator(file, SCHEDULER_CONFIG).build();

    ObjectMapper objectMapper = SerializationUtils.registerDefaultModules(new ObjectMapper());
    DefaultServiceSpec.ConfigFactory.GoalStateDeserializer goalStateDeserializer =
            ((DefaultServiceSpec.ConfigFactory) serviceSpec.getConfigurationFactory(serviceSpec))
                    .getGoalStateDeserializer();

    SimpleModule module = new SimpleModule();
    module.addDeserializer(GoalState.class, goalStateDeserializer);
    objectMapper.registerModule(module);

    Assert.assertEquals(
            GoalState.ONCE, SerializationUtils.fromString("\"ONCE\"", GoalState.class, objectMapper));
    Assert.assertEquals(
            GoalState.ONCE, SerializationUtils.fromString("\"FINISHED\"", GoalState.class, objectMapper));
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:21,代码来源:DefaultServiceSpecTest.java

示例13: getObjectMapper

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
public static ObjectMapper getObjectMapper() {
    if (mapper != null) {
        return mapper;
    }

    SimpleModule simpleLocalDateModule = new SimpleModule();
    simpleLocalDateModule.addSerializer(LocalDate.class, new SimpleLocalDateSerializer());
    simpleLocalDateModule.addDeserializer(LocalDate.class, new SimpleLocalDateDeserializer());
    mapper = new ObjectMapper()
            // adds JDK 8 Parameter Name access for cleaner JSON-to-Object mapping
            .registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES))
            .registerModule(simpleLocalDateModule);
    return mapper;
}
 
开发者ID:robinhowlett,项目名称:chart-parser,代码行数:15,代码来源:ChartParser.java

示例14: getModule

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
public static SimpleModule getModule() {
    final SimpleModule module = new SimpleModule();
    module.addSerializer(Class.class, (JsonSerializer) new SimpleClassSerializer());
    module.addDeserializer(Class.class, new SimpleClassDeserializer());
    module.addKeySerializer(Class.class, (JsonSerializer) new SimpleClassKeySerializer());
    module.addKeyDeserializer(Class.class, new SimpleClassKeyDeserializer());
    return module;
}
 
开发者ID:gchq,项目名称:koryphe,代码行数:9,代码来源:SimpleClassSerializer.java

示例15: ControllerJsonMapper

import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
/**
 * Initializes the JSON constructor.
 */
public ControllerJsonMapper() {
  super();
  SimpleModule module = new SimpleModule();
  module.addSerializer(Controller.class, ControllerSerializer.getInstance());
  module.addDeserializer(Controller.class, ControllerDeserializer.getInstance());
  super.registerModule(module);
  super.enable(SerializationFeature.INDENT_OUTPUT);
}
 
开发者ID:braineering,项目名称:ares,代码行数:12,代码来源:ControllerJsonMapper.java


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