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

nl.vpro.domain.media.bind.DurationToJsonTimestamp Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 8.3.1
Show newest version
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());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy