Skip to content

Please consider supporting Java 8 Date/Time type when serializing with Kryo #2178

Closed

Description

@kennyliao1982

Environment

  • Dubbo version: 2.6.2
  • Java version: 1.8

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);
    }
}

Activity

  1. 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
  2. added
    help wanted
    on Aug 3, 2018
  3. jtanza commented on Aug 3, 2018

    @jtanza

    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

  4. beiwei30 commented on Aug 5, 2018

    @beiwei30
    Member

    @jtanza, feel free to give it a try, pls. submit a pull request once you finish it :)

  5. jtanza commented on Aug 6, 2018

    @jtanza

    Awesome, will do!

  6. chickenlj commented on Aug 9, 2018

    @chickenlj
    Contributor

    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");
                }
                return new JavaSerializer();
            }
  7. chickenlj commented on Aug 9, 2018

    @chickenlj
    Contributor

    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.

  8. added a commit that references this issue on Aug 9, 2018
    260ef5d
  9. kennyliao1982 commented on Aug 10, 2018

    @kennyliao1982
    Author

    Thank you all guys for working on this issue.
    May I know what's the plan to release this fix??

  10. added a commit that references this issue on Aug 13, 2018
    8beeb64
  11. added this to the 2.6.6 milestone on Jan 25, 2019
  12. added a commit that references this issue on Feb 21, 2019
  13. added a commit that references this issue on Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanted

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions