Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9254669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:31:48+00:00 2026-06-18T11:31:48+00:00

Edit: Using Kryo 1.04 I’m right now serializing a User class that contains a

  • 0

Edit: Using Kryo 1.04

I’m right now serializing a User class that contains a java.sql.Timestamp field in Scala. For some reason, Kryo can’t find a zero-arg constructor and throws an error:

Caused by: com.esotericsoftware.kryo.SerializationException: Class cannot be created (missing no-arg constructor): java.sql.Timestamp
Serialization trace:
created (com.threetierlogic.AccountService.models.User)
        at com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:688)
        at com.esotericsoftware.kryo.Serializer.newInstance(Serializer.java:75)
        at com.esotericsoftware.kryo.serialize.FieldSerializer.readObjectData(FieldSerializer.java:200)
        at com.esotericsoftware.kryo.serialize.FieldSerializer.readObjectData(FieldSerializer.java:220)
        at com.esotericsoftware.kryo.serialize.FieldSerializer.readObjectData(FieldSerializer.java:200)
        at com.esotericsoftware.kryo.Serializer.readObject(Serializer.java:61)
        at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:589)
        ... 84 more
Caused by: java.lang.InstantiationException: java.sql.Timestamp
        at java.lang.Class.newInstance0(Class.java:340)
        at java.lang.Class.newInstance(Class.java:308)
        at com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:676)
        ... 90 more

This is part of a converter class to convert domain objects for Riak. Here’s my converter class:

/**
 * Kryo converter for passing domain objects into Riak
 */
class UserConverter(val bucket: String) extends Converter[User] {

  def fromDomain(domainObject: User, vclock: VClock): IRiakObject = {
    val key = domainObject.guid

    if(key == null) throw new NoKeySpecifedException(domainObject)

    val kryo = new Kryo()
    kryo.register(classOf[User])
    kryo.register(classOf[Timestamp])

    val ob = new ObjectBuffer(kryo)
    val value = ob.writeObject(domainObject)

    RiakObjectBuilder.newBuilder(bucket, key)
        .withValue(value)
        .withVClock(vclock)
        .withContentType(Constants.CTYPE_OCTET_STREAM)
        .build()
  }

  def toDomain(riakObject: IRiakObject): User = {
    if(riakObject == null) null

    val kryo = new Kryo()
    kryo.register(classOf[User])
    kryo.register(classOf[Timestamp])
    val ob = new ObjectBuffer(kryo)

    ob.readObject(riakObject.getValue(), classOf[User])
  }
}

Do I need to extend Timestamp and create a zero argument constructor? Or is there a better workaround?

If I need to upgrade to 2.20, what’s the replacement for ObjectBuffer without writing to a file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:31:50+00:00Added an answer on June 18, 2026 at 11:31 am

    You can do something like this :

      class KryoSO {
        import com.esotericsoftware.kryo.KryoSerializable
        import de.javakaffee.kryoserializers.KryoReflectionFactorySupport
        import com.esotericsoftware.kryo.Kryo
        import com.esotericsoftware.kryo.Serializer
        import java.io.{ InputStream, OutputStream }
        import com.esotericsoftware.kryo.io.{ Output, Input }
        import java.sql.Timestamp
    
        object TimestampSerializer extends Serializer[Timestamp] {
          override def write(kryo: Kryo, output: Output, t: Timestamp): Unit = {
            output.writeLong(t.getTime(), true);
          }
    
          override def read(kryo: Kryo, input: Input, t: Class[Timestamp]): Timestamp = {
            new Timestamp(input.readLong(true));
          }
    
          override def copy(kryo: Kryo, original: Timestamp): Timestamp = {
            new Timestamp(original.getTime());
          }
        }
        val kryo: Kryo = new KryoReflectionFactorySupport
        kryo.addDefaultSerializer(classOf[Timestamp], TimestampSerializer)
    
        def serialize(o: Any, os: OutputStream) = {
          val output = new Output(os);
          this.kryo.writeClassAndObject(output, o);
          output.flush();
        }
    
        def deserialize(is: InputStream): Any = {
          kryo.readClassAndObject(new Input(is));
        }
    
      }
      val k = new KryoSO
      val b = new java.io.ByteArrayOutputStream
      val timestamp = new java.sql.Timestamp(System.currentTimeMillis())
    
      k.serialize(timestamp, b)
    
      val result = k.deserialize(new java.io.ByteArrayInputStream(b.toByteArray()))
    
      println(timestamp)
      println(result.getClass)
      println(result.isInstanceOf[java.sql.Timestamp])
      println(timestamp == result)
    

    Result :

    2013-02-07 10:59:19.482
    class java.sql.Timestamp
    true
    true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that I want to edit using Java. It has
Edit: using SQL Server 2005. I have a query that has to check whether
How to get value of the field in Runtime for Java? EDIT: using this
EDIT: iam using ajax to load text in my content that is why onload
I am using Komodo Edit , a code editor. When I right click on
I have a page where the user can edit various content using buttons and
[EDIT: using a simplified test page without Javascript etc.] I've got a webpage that
EDIT: Using simpler code. I have a blackberry app that until recently (I upgraded
Given a std record edit form using WPF two way binding to a EF
I'm using Visual Studio 2008. I'm currently working with WPF and I'm using Edit->Format

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.