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

nl.vpro.domain.api.jackson.media.ScheduleEventSearchListJson Maven / Gradle / Ivy

Go to download

Contains the objects used by the Frontend API, like forms and result objects

There is a newer version: 8.3.3
Show newest version
package nl.vpro.domain.api.jackson.media;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

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.api.media.ScheduleEventSearch;

/**
 * @author Michiel Meeuwissen
 * @since 5.3
 */
public class ScheduleEventSearchListJson {

    private ScheduleEventSearchListJson() {
    }


    public static class Serializer extends JsonSerializer> {
        @Override
        public void serialize(List value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
            if (value.size() == 1) {
                jgen.writeObject(value.iterator().next());
            } else {
                jgen.writeStartArray();
                for (ScheduleEventSearch scheduleEventSearch : value) {
                    jgen.writeObject(scheduleEventSearch);
                }
                jgen.writeEndArray();
            }

        }
    }

    public static class Deserializer extends JsonDeserializer> {

        @Override
        public List deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
            if (jp.getParsingContext().inObject()) {
                jp.clearCurrentToken();
                ScheduleEventSearch scheduleEventSearch = jp.readValueAs(ScheduleEventSearch.class);
                return Arrays.asList(scheduleEventSearch);
            } else if (jp.getParsingContext().inArray()) {
                List list = new ArrayList<>();
                jp.clearCurrentToken();
                Iterator i = jp.readValuesAs(ScheduleEventSearch.class);
                while (i.hasNext()) {
                    list.add(i.next());
                }
                return list;
            } else {
                throw new IllegalStateException();
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy