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