本文整理匯總了Java中com.fasterxml.jackson.datatype.jsr310.JavaTimeModule.addDeserializer方法的典型用法代碼示例。如果您正苦於以下問題:Java JavaTimeModule.addDeserializer方法的具體用法?Java JavaTimeModule.addDeserializer怎麽用?Java JavaTimeModule.addDeserializer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
的用法示例。
在下文中一共展示了JavaTimeModule.addDeserializer方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convertObjectToJsonBytes
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //導入方法依賴的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();
module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
mapper.registerModule(module);
return mapper.writeValueAsBytes(object);
}
示例2: convertObjectToJsonBytes
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //導入方法依賴的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();
module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
module.addSerializer(JSONObject.class, JSONObjectSerializer.instance);
mapper.registerModule(module);
return mapper.writeValueAsBytes(object);
}
示例3: jackson2ObjectMapperBuilder
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //導入方法依賴的package包/類
@Bean
Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
JavaTimeModule module = new JavaTimeModule();
module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
return new Jackson2ObjectMapperBuilder()
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.findModulesViaServiceLoader(true)
.modulesToInstall(module);
}
示例4: jackson2ObjectMapperBuilder
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //導入方法依賴的package包/類
@Bean
Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
JavaTimeModule module = new JavaTimeModule();
module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
return new Jackson2ObjectMapperBuilder()
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.findModulesViaServiceLoader(true)
.modulesToInstall(module);
}
示例5: jackson2ObjectMapperBuilder
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //導入方法依賴的package包/類
@Bean
public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
JavaTimeModule module = new JavaTimeModule();
module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
return new Jackson2ObjectMapperBuilder()
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.findModulesViaServiceLoader(true)
.modulesToInstall(module);
}
示例6: jackson2ObjectMapperBuilder
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //導入方法依賴的package包/類
@Bean
Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
JavaTimeModule module = new JavaTimeModule();
module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
return new Jackson2ObjectMapperBuilder()
.findModulesViaServiceLoader(true)
.modulesToInstall(module);
}
示例7: convertObjectToJsonBytes
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //導入方法依賴的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();
module.addSerializer(ZonedDateTime.class, new ZonedDateTimeSerializer(ISO_FIXED_FORMAT));
module.addDeserializer(LocalDate.class, new LocalDateDeserializer(ISO_DATE_OPTIONAL_TIME));
mapper.registerModule(module);
return mapper.writeValueAsBytes(object);
}
示例8: jackson2ObjectMapperBuilder
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //導入方法依賴的package包/類
@Bean
Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
JavaTimeModule module = new JavaTimeModule();
module.addDeserializer(LocalDate.class, new CustomLocalDateDeserializer());
module.addSerializer(LocalDate.class, new CustomLocalDateSerializer());
module.addDeserializer(LocalDateTime.class, new CustomLocalDateTimeDeserializer());
module.addSerializer(LocalDateTime.class, new CustomLocalDateTimeSerializer());
return new Jackson2ObjectMapperBuilder().featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).findModulesViaServiceLoader(true)
.modulesToInstall(module);
}