You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Please consider supporting Java 8 Date/Time type when serializing with Kryo #2178
I am using java.time.LocalDateTime and Dubbo complains "class java.time.LocalDateTime has no zero-arg constructor and this will affect the serialization performance", which is caused by Dubbo's wrapper class "CompatibleKryo"
Any thoughts ??
package com.alibaba.dubbo.common.serialize.kryo;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.common.serialize.kryo.utils.ReflectionUtils;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.serializers.JavaSerializer;
public class CompatibleKryo extends Kryo {
private static final Logger logger = LoggerFactory.getLogger(CompatibleKryo.class);
@Override
public Serializer getDefaultSerializer(Class type) {
if (type == null) {
throw new IllegalArgumentException("type cannot be null.");
}
if (!type.isArray() && !type.isEnum() && !ReflectionUtils.checkZeroArgConstructor(type)) {
if (logger.isWarnEnabled()) {
logger.warn(type + " has no zero-arg constructor and this will affect the serialization performance");
}
return new JavaSerializer();
}
return super.getDefaultSerializer(type);
}
}
changed the title [-]please consider supporting Java 8 Date/Time type when serializing with Kryo[/-][+]Please consider supporting Java 8 Date/Time type when serializing with Kryo[/+]on Aug 3, 2018
hi, I haven't contributed before but would like to take this one on, is that okay? I am not actually sure of how to best address this one, but may get a better handle on things after taking a closer look at this portion of the code
I think this snippet works, only too much warn logs, is that right?
if (!type.isArray() && !type.isEnum() && !ReflectionUtils.checkZeroArgConstructor(type)) {
if (logger.isWarnEnabled()) {
logger.warn(type + " has no zero-arg constructor and this will affect the serialization performance");
}
returnnewJavaSerializer();
}
It seems that Kryo 4.0.1 used by Dubbo already support Java 8 Date types. It's the CompatibleKryo short-circuited that logic by checking zero-arg constructor.
Activity
[-]please consider supporting Java 8 Date/Time type when serializing with Kryo[/-][+]Please consider supporting Java 8 Date/Time type when serializing with Kryo[/+]jtanza commentedon Aug 3, 2018
hi, I haven't contributed before but would like to take this one on, is that okay? I am not actually sure of how to best address this one, but may get a better handle on things after taking a closer look at this portion of the code
beiwei30 commentedon Aug 5, 2018
@jtanza, feel free to give it a try, pls. submit a pull request once you finish it :)
jtanza commentedon Aug 6, 2018
Awesome, will do!
chickenlj commentedon Aug 9, 2018
I think this snippet works, only too much warn logs, is that right?
chickenlj commentedon Aug 9, 2018
It seems that Kryo 4.0.1 used by Dubbo already support Java 8 Date types. It's the CompatibleKryo short-circuited that logic by checking zero-arg constructor.
Fixes apache#2178, leave jdk standard classes to kryo itself.
kennyliao1982 commentedon Aug 10, 2018
Thank you all guys for working on this issue.
May I know what's the plan to release this fix??
Merge pull request #2220, leave jdk standard classes to kryo, use the…
apply #2220 to 2.6.x branch, issue #2178 (#3519)
fix default setting (#4955)