ical4j / ical4j-serializer

Marshalling iCalendar and vCard to XML and JSON formats
http://www.ical4j.org/serializer/
BSD 3-Clause "New" or "Revised" License
2 stars 2 forks source link

jCal JSON format #11

Open carcohcal opened 2 years ago

carcohcal commented 2 years ago

Hi,

I'm trying to use the jCal JSON example but it isn't working:

Calendar calendar = ...;
SimpleModule module = new SimpleModule();
module.addSerializer(Calendar.class, new JCalSerializer());
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);

String serialized = mapper.writeValueAsString(calendar);

The first issue I encounter is the need to set an entry parameter in the JCalSerializer.

Jcal_error

I added Calendar.class and compiles OK but while executing the following exception occurs in this line

String serialized = mapper.writeValueAsString(calendar);

java.lang.NoSuchMethodError: net.fortuna.ical4j.model.PropertyList.iterator()Ljava/util/Iterator;
    at org.mnode.ical4j.serializer.JCalSerializer.buildVCalendar(JCalSerializer.java:36) ~[ical4j-serializer-0.1.6.jar:na]
    at org.mnode.ical4j.serializer.JCalSerializer.serialize(JCalSerializer.java:26) ~[ical4j-serializer-0.1.6.jar:na]
    at org.mnode.ical4j.serializer.JCalSerializer.serialize(JCalSerializer.java:18) ~[ical4j-serializer-0.1.6.jar:na]
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) ~[jackson-databind-2.13.0.jar:2.13.0]
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319) ~[jackson-databind-2.13.0.jar:2.13.0]
    at com.fasterxml.jackson.databind.ObjectMapper._writeValueAndClose(ObjectMapper.java:4569) ~[jackson-databind-2.13.0.jar:2.13.0]
    at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3822) ~[jackson-databind-2.13.0.jar:2.13.0]

I check the calendar and it has properties and components. I don't know if I'm doing something wrong or there is a bug.

Thanks

benfortuna commented 2 years ago

Thanks for the early feedback.

Can you confirm which version of ical4j you are using? The tests are currently run with ical4j v3.1.1.

carcohcal commented 2 years ago

Thanks for the early feedback.

Can you confirm which version of ical4j you are using? The tests are currently run with ical4j v3.1.1.

Hi,

I'm using gradle with the following versions:

'org.mnode.ical4j:ical4j:4.0.0-alpha9' 'org.mnode.ical4j:ical4j-serializer:0.1.6'

benfortuna commented 2 years ago

Unfortunately ical4j v4 has a number of incompatible API changes that are not yet supported in ical4j-serializer. Once the final release of v4 is announced we will look to transition other libraries to the new API.

carcohcal commented 2 years ago

I change ical API version but still have some issues.

I use the ical -> json function to serialize my calendar:

private String ICALaJSON(Calendar calendar) throws JsonProcessingException {

        SimpleModule module = new SimpleModule();
        module.addSerializer(Calendar.class, new JCalSerializer((Calendar.class)));
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(module);

        String serialized = mapper.writeValueAsString(calendar);

        System.out.println(serialized);
        return serialized;

    }

For testing that serialize string is passed to the the json -> ical conversion function. I have the following function:

private void JSONaIcal(String json) throws JsonMappingException, JsonProcessingException {

        SimpleModule module = new SimpleModule();
        module.addDeserializer(Calendar.class, new JCalMapper(Calendar.class));
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(module);

        Calendar calendar = mapper.readValue(json, Calendar.class);
        log.info("CONTROL");

    }

But the following error occurs:

 Caught DateTimeException: Text '2021-12-16T19:20:59Z' could not be parsed, unparsed text found at index 19

It is related to [["dtstamp",{},"date-time","2021-12-16T19:20:59Z"]

Thanks