Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Is Kotlin data class serializable by default?

After knowing Kotlin, love the data class. I could replace Java classes that has equal and hash and toString to it. Most of these Java classes are serializable class. So my question is, when we convert to data class, do I still need to make it serializable explicitly? like

data class SomeJavaToKotlinClass(val member: String) : Serializable

Or it is okay to be

data class SomeJavaToKotlinClass(val member: String)
over 4 years ago · Hanz Gallego
2 answers
Answer question

0

No, Kotlin data classes do not implicitly implement this interface. You can see from this example:

import java.io.Serializable

data class Foo(val bar: String)

fun acceptsSerializable(s: Serializable) { }

fun main(args: Array<String>) {
    val f: Foo = Foo("baz")
    acceptsSerializable(f)  // Will not compile
}
over 4 years ago · Hanz Gallego Report

0

I had to add : Serializable at the end of class to make is Serializable. Just like this

class SizeVariantModel (val price: Double, val discountedPrice: Double?) : Serializable
class ColorVariantModel (val name: String, val colorCode: String) : Serializable

I also had to import Serializable

import java.io.Serializable
over 4 years ago · Hanz Gallego Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!