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

org.mnode.ical4j.json.jscalendar.JSTaskSerializer Maven / Gradle / Ivy

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

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.ConstraintViolationException;
import net.fortuna.ical4j.model.component.VToDo;

import java.io.IOException;

public class JSTaskSerializer extends StdSerializer {

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

    @Override
    public void serialize(VToDo value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        try {
            gen.writeTree(buildJSTask(value));
        } catch (ConstraintViolationException e) {
            throw new RuntimeException(e);
        }
    }

    private JsonNode buildJSTask(VToDo toDo) throws ConstraintViolationException {
        AbstractJSCalendarBuilder builder = new JSTaskBuilder().component(toDo);
        return builder.build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy