org.mnode.ical4j.json.jot.JotCardMapper 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.jot;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import net.fortuna.ical4j.vcard.VCard;
import org.apache.commons.codec.DecoderException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.ParseException;
public class JotCardMapper extends AbstractJotCardMapper {
public JotCardMapper(Class t) {
super(t);
}
@Override
public VCard deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
VCard card = new VCard();
assertCurrentToken(p, JsonToken.START_OBJECT);
while (!JsonToken.END_OBJECT.equals(p.nextToken())) {
assertCurrentToken(p, JsonToken.FIELD_NAME);
String propertyName = p.currentName();
try {
if (JsonToken.START_ARRAY.equals(p.nextToken())) {
card.getProperties().addAll(parsePropertyList(propertyName, p));
} else {
card.getProperties().add(parseProperty(propertyName, p));
}
} catch (URISyntaxException | ParseException | DecoderException e) {
throw new IllegalArgumentException(e);
}
}
return card;
}
}