-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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;
}
}
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
I've created the tracker ticket: https://tracker.zkoss.org/browse/ZKCAL-104
Asked: 2023-03-23 00:36:00 +0800
Seen: 13 times
Last updated: Apr 10
How to set any day/week/month as default view in zk-calendar [closed]
How to disable the event ghost in ZK Calendar?
How to disable past days in ZK Calendar?
Components below the fold are clickable when using modal window
Spring security login after server reload