当前位置: 首页>>代码示例>>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;未经允许,请勿转载。