本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.registerModule方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.registerModule方法的具体用法?Java ObjectMapper.registerModule怎么用?Java ObjectMapper.registerModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.ObjectMapper
的用法示例。
在下文中一共展示了ObjectMapper.registerModule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSystemEvent
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private String createSystemEvent(String tenant, String command) {
SystemEvent event = new SystemEvent();
event.setEventId(MDCUtil.getRid());
event.setEventType(command);
event.setTenantInfo(TenantContext.getCurrent());
event.setMessageSource(appName);
event.getData().put(Constants.EVENT_TENANT, tenant);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
try {
return mapper.writeValueAsString(event);
} catch (JsonProcessingException e) {
log.error("System Event mapping error", e);
throw new BusinessException("Event mapping error", e.getMessage());
}
}
示例2: write
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private static void write(Contingency object, Path jsonFile) {
Objects.requireNonNull(object);
Objects.requireNonNull(jsonFile);
try (OutputStream os = Files.newOutputStream(jsonFile)) {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(ContingencyElement.class, new ContingencyElementSerializer());
mapper.registerModule(module);
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
writer.writeValue(os, object);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例3: testModalTypeSerialization
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testModalTypeSerialization() {
String expected = "{\"type\":\"IndividualTrip\",\"uuid\":null,\"start\":null,\"end\":null,\"status\":null," +
"\"lengthInM\":0.0,\"messageList\":null,\"modalType\":\"walk\",\"isAccessible\":null," +
"\"ticketMatches\":null,\"pathDataSource\":null,\"pathData\":null,\"durationInS\":null}";
IndividualTrip trip = new IndividualTrip.Builder().withModalType(ModalType.walk).build();
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
mapper.addMixInAnnotations(IndividualTrip.class, UraIndividualTripMixIn.class);
Writer stringWriter = new StringWriter();
try {
mapper.writeValue(stringWriter, trip);
String json = stringWriter.toString();
assertNotNull(json);
assertEquals(json, expected);
} catch (Exception e) {
fail();
}
}
示例4: createObjectMapper
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private static ObjectMapper createObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(new ParameterNamesModule());
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
return mapper;
}
示例5: toJSONString
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
* Produces a string containing a JSON representation of the object. The
* default implementation just falls back to Jackson Java 8 serialization
*
* @return A {@code String} containing JSON
*/
public default String toJSONString() {
try {
final ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
return mapper.writeValueAsString(this);
} catch (JsonProcessingException jsonx) {
throw new RuntimeException(jsonx);
}
}
示例6: initObjectMapper
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private void initObjectMapper(CrnkFeature feature) {
ObjectMapper objectMapper = feature.getObjectMapper();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.registerModule(new JavaTimeModule());
objectMapper.findAndRegisterModules();
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
示例7: parse
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
* Generic helper method that takes a string and a mapping function
*
* @param <E> The desired output type
* @param parseText The input data to be parsed
* @param fn A {@code Function} object to take a string bag and produce an instance of {@code E}
* @return An instance of {@code E}
*/
public static <E> E parse(final String parseText, final Function<Map<String, ?>, E> fn) {
final ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
try {
return fn.apply(mapper.readValue(parseText, new TypeReference<Map<String, ?>>() {
}));
} catch (IOException iox) {
throw new RuntimeException(iox);
}
}
示例8: benchSetup
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) {
objectMapper = new ObjectMapper();
objectMapper.registerModule(new AfterburnerModule());
typeReference = new TypeReference<TestObject>() {
};
testJSON = TestObject.createTestJSON();
}
示例9: convertObjectToJsonBytes
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
* Convert an object to JSON byte array.
*
* @param object
* the object to convert
* @return the JSON byte array
* @throws IOException
*/
public static byte[] convertObjectToJsonBytes(Object object)
throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JavaTimeModule module = new JavaTimeModule();
mapper.registerModule(module);
return mapper.writeValueAsBytes(object);
}
示例10: customObjectMapperForSpring
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
* Example how skip auto-configuration and use a custom ObjectMapper.
* Also can use a Jackson2ObjectMapperBuilder bean for the same purpose.
*/
//@Bean
ObjectMapper customObjectMapperForSpring() {
ObjectMapper mapper = new ObjectMapper();
JavaTimeModule javaTimeModule = new JavaTimeModule();
javaTimeModule.addSerializer(new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("YYYY-MMM")));
mapper.registerModule(javaTimeModule);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.setDateFormat(new SimpleDateFormat("YYYY"));
return mapper;
}
示例11: mappingJackson2HttpMessageConverter
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
jsonConverter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
objectMapper.registerModule(new Jackson2HalModule());
jsonConverter.setObjectMapper(objectMapper);
return jsonConverter;
}
示例12: NykreditJsonProvider
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public NykreditJsonProvider(ObjectMapper mapper) {
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(new Jdk8Module());
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
setMapper(mapper);
}
示例13: camelToKebabObjectMapper
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private ObjectMapper camelToKebabObjectMapper(SimpleModule sm) {
ObjectMapper jsonMapper = new ObjectMapper();
jsonMapper.setPropertyNamingStrategy(new CamelCaseToKebabCaseNamingStrategy());
if (sm != null) {
jsonMapper.registerModule(sm);
}
jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return jsonMapper;
}
示例14: serializeAnnotatedType
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void serializeAnnotatedType() throws Exception {
PersonGroup group = new PersonGroup(1L, "group1", "思考、距离、俘获", new ArrayList<Person>(), "距离产生美");
Person p1 = new Person(1L, "chaokunyang", "男", 23, "快与慢", group);
Person p2 = new Person(1L, "chaokunyang", "男", 23, "快与慢", group);
group.getPersons().add(p1);
group.getPersons().add(p2);
SimpleModule module = new SimpleModule();
Set<Class<?>> annotatedClasses = ClassUtils.getAnnotatedClasses("com.timeyang.search.entity", Document.class);
annotatedClasses.forEach(aClass -> module.addSerializer(aClass, new JkesJsonSerializer<>()));
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
String groupResult = mapper.writeValueAsString(group); // 序列化
assertThat(groupResult, containsString("group1"));
assertNotEquals(groupResult, containsString("距离产生美"));
assertNotEquals(groupResult, containsString("快与慢"));
System.out.println(groupResult);
String p1Result = mapper.writeValueAsString(p1); // 序列化
assertNotEquals(p1Result, containsString("chaokunyang"));
System.out.println(p1Result);
String p2Result = mapper.writeValueAsString(p2); // 序列化
assertNotEquals(p2Result, containsString("chaokunyang"));
System.out.println(p2Result);
}
示例15: LoadSaveString
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public void LoadSaveString(String loadString) {
try {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
this.loadString = loadString;
mapper.registerModule(module);
//New instance of the JSONObject, being initialized, from the loadString
JSONObject json = new JSONObject(loadString);
//all the instances of rooms, and the player, which where serialized and saved in a file, gets read, as single objects, and their info, put into a string, containing only the that info
String playerPart = json.getJSONObject("player").toString();
String medbayPart = json.getJSONObject("Medbay").toString();
String Hallway = json.getJSONObject("Hallway").toString();
String Keyroom = json.getJSONObject("Keyroom").toString();
String Communicationroom = json.getJSONObject("Communicationroom").toString();
String Armoury = json.getJSONObject("Armoury").toString();
String Airlock = json.getJSONObject("Airlock").toString();
String Currentroom = json.getJSONObject("Currentroom").toString();
//Here a new player1, gets initialized, from the string playerPart, and deserialized into a Player.class.
Player player1 = mapper.readValue(playerPart, Player.class);
//Here the Rooms get initialized from their respective strings, and deserialized, into the Room.class
Room medbay = mapper.readValue(medbayPart, Room.class);
Room Hallway1 = mapper.readValue(Hallway, Room.class);
Room Keyroom1 = mapper.readValue(Keyroom, Room.class);
Room Communicationroom1 = mapper.readValue(Communicationroom, Room.class);
Room Armoury1 = mapper.readValue(Armoury, Room.class);
Room Airlock1 = mapper.readValue(Airlock, Room.class);
String Currentroom1 = mapper.readValue(Currentroom, Room.class).getName();
//Here the deserialized player and rooms, get set into the game class, as the new player and rooms, with all the info, from when the user saved the game
game.setPlayer(player1);
game.setMedbay(medbay);
game.setHallway(Hallway1);
game.setKeyRoom(Keyroom1);
game.setCommunicationRoom(Communicationroom1);
game.setArmoury(Armoury1);
game.setAirlock(Airlock1);
game.setCurrentRoom(Currentroom1);
} catch (JSONException | IOException ex) {
Logger.getLogger(SaveFile.class.getName()).log(Level.SEVERE, null, ex);
}
}