Created
September 3, 2015 09:00
-
-
Save MarioAriasC/de3676ac18e84e1c2703 to your computer and use it in GitHub Desktop.
Kryo serialization works out-of-the-box with Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.cakesolutions.spark.kryo | |
import com.esotericsoftware.kryo.Kryo | |
import com.esotericsoftware.kryo.io.Input | |
import com.esotericsoftware.kryo.io.Output | |
import java.io.FileInputStream | |
import java.io.FileOutputStream | |
fun main(args: Array<String>) { | |
val kryo = Kryo() | |
val output = Output(FileOutputStream("file.bin")) | |
val user = User("Mario", Address("Manchester", "Flat 86", "M###XX")) | |
kryo.writeObject(output, user) | |
output.close() | |
val input = Input(FileInputStream("file.bin")) | |
val u = kryo.readObject(input, javaClass<User>()) | |
input.close() | |
println("u = ${u}") | |
} | |
data class Address(val city: String? = null, val line: String? = null, val postCode: String? = null) | |
data class User(val name: String? = null, | |
val address: Address? = null) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment