nl.vpro.domain.media.bind.DurationToJsonTimestamp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of media-domain Show documentation
Show all versions of media-domain Show documentation
The basic domain classes for 'media', the core of POMS. Also, the 'update' XML bindings for it.
It also contains some closely related domain classes like the enum to contain NICAM kijkwijzer settings.
package nl.vpro.domain.media.bind;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import nl.vpro.domain.media.support.AuthorizedDuration;
/**
* Adapts the Duration of the media domain. (This actually contains an 'authority', but we don't expose that in json).
* @author Michiel Meeuwissen
* @since 2.3
*/
public class DurationToJsonTimestamp {
public static class Serializer extends JsonSerializer {
@Override
public void serialize(AuthorizedDuration value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
if (value == null || value.get() == null) {
jgen.writeNull();
} else {
jgen.writeNumber(value.get().toMillis());
}
}
}
/**
* @since 2.0
*/
public static class Deserializer extends JsonDeserializer {
@Override
public AuthorizedDuration deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return AuthorizedDuration.ofMillis(jp.getLongValue());
}
}
}