當前位置: 首頁>>代碼示例>>Java>>正文


Java JavaTimeModule.addSerializer方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.datatype.jsr310.JavaTimeModule.addSerializer方法的典型用法代碼示例。如果您正苦於以下問題:Java JavaTimeModule.addSerializer方法的具體用法?Java JavaTimeModule.addSerializer怎麽用?Java JavaTimeModule.addSerializer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.datatype.jsr310.JavaTimeModule的用法示例。


在下文中一共展示了JavaTimeModule.addSerializer方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:24,代碼來源:TestUtil.java

示例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);
}
 
開發者ID:OwnYourData,項目名稱:oyd-pia,代碼行數:25,代碼來源:TestUtil.java

示例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);
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:14,代碼來源:JacksonConfiguration.java

示例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);
}
 
開發者ID:ugouku,項目名稱:shoucang,代碼行數:14,代碼來源:JacksonConfiguration.java

示例5: customObjectMapperForSpring

import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //導入方法依賴的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;
}
 
開發者ID:bszeti,項目名稱:camel-springboot,代碼行數:15,代碼來源:AppConfig.java

示例6: 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));
    mapper.registerModule(module);

    return mapper.writeValueAsBytes(object);
}
 
開發者ID:flanciskinho,項目名稱:prove.jwt,代碼行數:20,代碼來源:TestUtil.java

示例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);
}
 
開發者ID:axel-halin,項目名稱:Thesis-JHipster,代碼行數:21,代碼來源:TestUtil.java


注:本文中的com.fasterxml.jackson.datatype.jsr310.JavaTimeModule.addSerializer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。