com.github.marceloleite2604.util.time.duration.serializer.DurationToIso8601FormatSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of util Show documentation
Show all versions of util Show documentation
A series of useful classes and methods which helps on minor tasks.
package com.github.marceloleite2604.util.time.duration.serializer;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
import java.time.Duration;
/**
*
* A {@link StdSerializer} extension to serialize {@link Duration} objects to a ISO-8601 formatted
* text.
*
*
* Its deserialization equivalent can be found on {@link DurationFromIso8601FormatDeserializer}
* class.
*
*
* @author MarceloLeite2604
*
*/
public class DurationToIso8601FormatSerializer extends StdSerializer {
private static final long serialVersionUID = 1L;
public DurationToIso8601FormatSerializer() {
super(Duration.class);
}
@Override
public void serialize(Duration duration, JsonGenerator jsonGenerator,
SerializerProvider serializer) throws IOException {
jsonGenerator.writeString(duration.toString());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy