0

Issue with Serialization SimpleCalendarItem - zk.Calendar<3.1.1>

asked 2023-03-23 00:36:00 +0800

ypaz gravatar image ypaz
1

Hello! I'm a developer who work with ZK.

We have an issue with the class serialization when we use the calendar class SimpleCalendarItem which extends AbstractCalendarItem<date>

The error in the console is:

org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.InvalidClassException: ch.unil.calendar.core.domain.EventCourses; no valid constructor

We have made an unit test to show the same error:

import ch.unil.calendar.core.domain.EventCourses;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
@Test
void should_be_able_to_serialize_and_deserialize_event_courses_with_jdk_redis_serializer() {
EventCourses eventCourses = new EventCourses();
JdkSerializationRedisSerializer serializer = new JdkSerializationRedisSerializer();
byte[] bytes = serializer.serialize(eventCourses);
Object object = serializer.deserialize(bytes);
System.out.println(object);
}

class EventCourses (us) extends EventCalendar (us) and EventCalendar extends SimpleCalendarItem (zk - you)

We use the data redis to serializable the classes. We think that is the SimpleCalendarItem class that it's not serialize in the best way.

What do you think about that ? I explain correctly the issue ? :)

Thank you.

Yvan

delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2023-03-28 16:16:13 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

SimpleCalendarItem does implement serializable, so it would expected to serialize / deserialize

From a quick search, the issue could be that the parent class of SimpleCalendarItem (org.zkoss.calendar.impl.AbstractCalendarItem<t>) doesn't have a no-arg constructor.

Try adding the class below to your project under package org.zkoss.calendar.impl (to override the default AbstractCalendarItem class) and check if it still fails. This class adds a no-arg constructor to the AbstractCalendarItem.

Let me know if this does in fact solves the serialization issue. If so we can make a bug ticket about it.

Class here:

    /* AbstractCalendarItem.java

        Purpose:

        Description:

        History:
                Tue Jan 12 09:34:16 CST 2021, Created by leon

Copyright (C) 2021 Potix Corporation. All Rights Reserved.
*/
package org.zkoss.calendar.impl;

import java.time.Instant;
import java.util.HashMap;
import java.util.Map;

import org.zkoss.calendar.api.CalendarItem;
import org.zkoss.util.Maps;

/**
 * A skeletal implementation for {@link CalendarItem}
 * @author leon
 * @since 3.0.0
 */
public abstract class AbstractCalendarItem<T> implements CalendarItem {
    protected String _title;
    protected String _content;
    protected String _sclass;
    protected String _style;
    protected String _contentStyle;
    protected String _headerStyle;
    protected boolean _locked;
    protected T _begin;
    protected T _end;

    public AbstractCalendarItem() {
        /* necessary for deserialization?*/
    }

    @Deprecated
    public AbstractCalendarItem(String title, String content, String headerColor, String contentColor, boolean locked, T begin, T end) {
        this(title, content, headerColor, contentColor, "", locked, begin, end);
    }

    public AbstractCalendarItem(String title, String content, String style, String contentStyle, String headerStyle, boolean locked, T begin, T end) {
        this._title = title;
        this._content = content;
        this._style = style;
        this._contentStyle = contentStyle;
        this._headerStyle = headerStyle;
        this._locked = locked;
        this._begin = begin;
        this._end = end;
    }
    public AbstractCalendarItem(String title, String content, String sclass, String style, String contentStyle, String headerStyle, boolean locked, T begin, T end) {
        this(title, content, style, contentStyle, headerStyle, locked, begin, end);
        this._sclass = sclass;
    }

    public Instant getBegin() {
        return convertToInstant(_begin);
    }

    public Instant getEnd() {
        return convertToInstant(_end);
    }

    protected abstract Instant convertToInstant(T date);

    @Override
    public String getTitle() {
        return _title;
    }

    @Override
    public String getContent() {
        return _content;
    }

    @Override
    @Deprecated
    public String getHeaderColor() {
        Map styleMap = new HashMap<>();
        Maps.parse(styleMap, this._headerStyle, ':', ';', (char)0);
        return (String) styleMap.get("background-color");
    }

    @Override
    @Deprecated
    public String getContentColor() {
        Map styleMap = new HashMap<>();
        Maps.parse(styleMap, this._style, ':', ';', (char)0);
        return (String) styleMap.get("background-color");
    }

    @Override
    public String getStyle() {
        return _style;
    }

    @Override
    public String getContentStyle() {
        return _contentStyle;
    }

    @Override
    public String getHeaderStyle() {
        return _headerStyle;
    }
    @Override
    public String getZclass() {
        return "z-calitem";
    }

    @Override
    public String getSclass() {
        return _sclass;
    }

    @Override
    public boolean isLocked() {
        return _locked;
    }
}
link publish delete flag offensive edit
0

answered 2023-03-29 19:19:07 +0800

ypaz gravatar image ypaz
1

Hello,

Thanks for the quick response.

Yes, it's a solution for us issue. In this moment, the serialization is working with the change that you have made.

You will create a ticket for this issue or what are you going to do ?

Thanks,

Yvan

link publish delete flag offensive edit
0

answered 2023-04-10 16:27:22 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

I've created the tracker ticket: https://tracker.zkoss.org/browse/ZKCAL-104

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2023-03-23 00:36:00 +0800

Seen: 13 times

Last updated: Apr 10 '23

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More