All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fizzed.crux.jackson.JavaTimePlusModule Maven / Gradle / Ivy

There is a newer version: 1.0.48
Show newest version
package com.fizzed.crux.jackson;

import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

public class JavaTimePlusModule {
    
    static public final ZoneId TZ_UTC = ZoneId.of("Z");
    
    static public JavaTimeModule build() {
        return build(true);
    }
    
    static public JavaTimeModule build(
            boolean strictDeserializing) {
        
        return build(strictDeserializing, ChronoUnit.MILLIS);
    }
    
    static public JavaTimeModule build(
            boolean strictDeserializing,
            ChronoUnit truncateTo) {
        
        final JavaTimeModule module = new JavaTimeModule();
        
        module.addSerializer(Instant.class, new JavaInstantSerializer());
        module.addDeserializer(Instant.class, new JavaInstantDeserializer(strictDeserializing, truncateTo));
        
        module.addSerializer(ZonedDateTime.class, new JavaZonedDateTimeSerializer());
        module.addDeserializer(ZonedDateTime.class, new JavaZonedDateTimeDeserializer(strictDeserializing, TZ_UTC, truncateTo));
        
        return module;
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy