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

org.mnode.ical4j.json.jot.JotAvailabilitySerializer Maven / Gradle / Ivy

The newest version!
package org.mnode.ical4j.json.jot;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import net.fortuna.ical4j.model.component.VAvailability;

import java.io.IOException;

/**
 * Convert iCal4j {@link VAvailability} objects to Jot JSON format.
 *
 * NOTE: Conversion to jot is "lossy" in that child components are ignored. This is intentional as
 * Jot JSON separates calendars and components into separate (not nested) JSON structures.
 */
public class JotAvailabilitySerializer extends StdSerializer {

    public JotAvailabilitySerializer(Class t) {
        super(t);
    }

    @Override
    public void serialize(VAvailability value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeTree(buildAvailability(value));
    }

    private JsonNode buildAvailability(VAvailability availability) {
        AbstractJotBuilder builder = new ComponentBuilder()
                .component(availability);
        return builder.build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy