Skip to content

Commit

Permalink
wip option
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Oct 24, 2019
1 parent 5a92e3d commit 7cb2e3d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 46 deletions.
37 changes: 37 additions & 0 deletions src/main/kotlin/com/sksamuel/avro4k/arrow/OptionSerializer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.sksamuel.avro4k.arrow

import arrow.core.Option
import com.sksamuel.avro4k.decoder.ExtendedDecoder
import com.sksamuel.avro4k.encoder.ExtendedEncoder
import com.sksamuel.avro4k.serializer.AvroSerializer
import kotlinx.serialization.Encoder
import kotlinx.serialization.SerialDescriptor
import kotlinx.serialization.Serializer
import org.apache.avro.Schema
import java.time.LocalDate

//class Tuple2Serializer : AvroSerializer<Tuple2<*, *>>() {
//
// override fun encodeAvroValue(schema: Schema, encoder: ExtendedEncoder, obj: Tuple2<*, *>) {
// }
//
// override fun decodeAvroValue(schema: Schema, decoder: ExtendedDecoder): Tuple2<*, *> {
// TODO()
// }
//
// override val descriptor: SerialDescriptor
// get() = TODO()
//}
//

@Serializer(forClass = Option::class)
class OptionSerializer<A> : AvroSerializer<Option<A>>() {

override fun encodeAvroValue(schema: Schema, encoder: ExtendedEncoder, obj: Option<A>) {
}

override fun decodeAvroValue(schema: Schema, decoder: ExtendedDecoder): Option<A> {
}


}
46 changes: 0 additions & 46 deletions src/main/kotlin/com/sksamuel/avro4k/arrow/Tuple2Serializer.kt

This file was deleted.

20 changes: 20 additions & 0 deletions src/test/kotlin/com/sksamuel/avro4k/arrow/OptionSchemaTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.sksamuel.avro4k.arrow

import arrow.core.Option
import com.sksamuel.avro4k.Avro
import io.kotlintest.shouldBe
import io.kotlintest.specs.FunSpec
import kotlinx.serialization.Serializable

class OptionSchemaTest : FunSpec({

test("options of primitives as basic unions") {

@Serializable
data class Test(@Serializable(OptionSerializer::class) val b: Option<String>)

val schema = Avro.default.schema(Test.serializer())
val expected = org.apache.avro.Schema.Parser().parse(javaClass.getResourceAsStream("/option.json"))
schema shouldBe expected
}
})
1 change: 1 addition & 0 deletions src/test/resources/option.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit 7cb2e3d

Please sign in to comment.