-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added java string option to ReflectionSchemaBuilder
- Loading branch information
Showing
4 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,9 @@ enum class UserType { User, Admin } | |
fun main() { | ||
|
||
val user = User(Random.nextLong(), "sammy mcsamface", "[email protected]", Random.nextLong(), UserType.Admin) | ||
val schema = ReflectionSchemaBuilder().schema(User::class) | ||
val schema = ReflectionSchemaBuilder(true).schema(User::class) | ||
|
||
GenericData.setStringType(schema, GenericData.StringType.String) | ||
|
||
repeat(5) { | ||
val time = measureTime { | ||
|
22 changes: 22 additions & 0 deletions
22
centurion-avro/src/test/kotlin/com/sksamuel/centurion/avro/encoders/StringEncoderTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.sksamuel.centurion.avro.encoders | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.types.shouldBeTypeOf | ||
import org.apache.avro.SchemaBuilder | ||
import org.apache.avro.generic.GenericData | ||
import org.apache.avro.util.Utf8 | ||
|
||
class StringEncoderTest : FunSpec({ | ||
|
||
test("should use java string when prop is set") { | ||
val schema = SchemaBuilder.builder().stringType() | ||
GenericData.setStringType(schema, GenericData.StringType.String) | ||
StringEncoder.encode(schema, "hello").shouldBeTypeOf<String>() | ||
} | ||
|
||
test("should use Utf8 when prop is not set") { | ||
val schema = SchemaBuilder.builder().stringType() | ||
StringEncoder.encode(schema, "hello").shouldBeTypeOf<Utf8>() | ||
} | ||
|
||
}) |