org.mnode.ical4j.json.jscalendar.JSEventSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ical4j-json Show documentation
Show all versions of ical4j-json Show documentation
Custom marshalling between iCal4j objects and JSON formats
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.VEvent;
import java.io.IOException;
public class JSEventSerializer extends StdSerializer {
public JSEventSerializer(Class t) {
super(t);
}
@Override
public void serialize(VEvent value, JsonGenerator gen, SerializerProvider provider) throws IOException {
try {
gen.writeTree(buildJSEvent(value));
} catch (ConstraintViolationException e) {
throw new RuntimeException(e);
}
}
private JsonNode buildJSEvent(VEvent event) throws ConstraintViolationException {
AbstractJSCalendarBuilder builder = new JSEventBuilder().component(event);
return builder.build();
}
}