-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working example based on avro-kotlin-serialization snapshot
- Loading branch information
1 parent
13b6d93
commit 986a168
Showing
46 changed files
with
203 additions
and
587 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
4 changes: 2 additions & 2 deletions
4
lib/fixtures/src/main/kotlin/bankaccount/command/CreateBankAccount.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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package bankaccount.command | ||
|
||
import bankaccount.conversions.MoneySerializer | ||
import bankaccount.conversions.MoneyLogicalType | ||
import kotlinx.serialization.Serializable | ||
import org.javamoney.moneta.Money | ||
|
||
@Serializable | ||
data class CreateBankAccount( | ||
val accountId: String, | ||
@Serializable(with = MoneySerializer::class) | ||
@Serializable(with = MoneyLogicalType.MoneySerializer::class) | ||
val initialBalance: Money | ||
) { | ||
} |
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
2 changes: 1 addition & 1 deletion
2
lib/fixtures/src/main/kotlin/bankaccount/query/CurrentBalance.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
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
24 changes: 0 additions & 24 deletions
24
lib/logical-types/src/main/kotlin/bankaccount/conversions/MoneyConversion.kt
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
lib/logical-types/src/main/kotlin/bankaccount/conversions/MoneyLogicalType.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,51 @@ | ||
package bankaccount.conversions | ||
|
||
import io.toolisticon.avro.kotlin.logical.StringLogicalType | ||
import io.toolisticon.avro.kotlin.logical.StringLogicalTypeFactory | ||
import io.toolisticon.avro.kotlin.logical.conversion.StringLogicalTypeConversion | ||
import io.toolisticon.avro.kotlin.logical.conversion.TypeConverter | ||
import io.toolisticon.avro.kotlin.value.LogicalTypeName.Companion.toLogicalTypeName | ||
import io.toolisticon.kotlin.avro.serialization.serializer.StringLogicalTypeSerializer | ||
import io.toolisticon.kotlin.avro.serialization.spi.AvroSerializerModuleFactory | ||
import kotlinx.serialization.modules.SerializersModule | ||
import org.javamoney.moneta.Money | ||
import java.util.* | ||
import javax.money.format.AmountFormatQuery | ||
import javax.money.format.MonetaryFormats | ||
|
||
|
||
object MoneyLogicalType : StringLogicalType("money".toLogicalTypeName()) { | ||
|
||
val convertedType = Money::class | ||
val conversion = MoneyConversion() | ||
|
||
val converter = object : TypeConverter<String, Money> { | ||
private val format = MonetaryFormats.getAmountFormat(AmountFormatQuery.of(Locale.GERMAN)) | ||
|
||
override fun fromAvro(value: String): Money { | ||
return Money.from(format.parse(value)) | ||
} | ||
|
||
override fun toAvro(value: Money): String { | ||
return format.format(value) | ||
} | ||
} | ||
|
||
class MoneyLogicalTypeFactory : StringLogicalTypeFactory<MoneyLogicalType>(logicalType = MoneyLogicalType) | ||
|
||
class MoneyConversion : StringLogicalTypeConversion<MoneyLogicalType, Money>( | ||
logicalType = MoneyLogicalType, | ||
convertedType = convertedType | ||
) { | ||
override fun fromAvro(value: String): Money = converter.fromAvro(value) | ||
override fun toAvro(value: Money): String = converter.toAvro(value) | ||
} | ||
|
||
class MoneySerializer : StringLogicalTypeSerializer<MoneyLogicalType, Money>(conversion) | ||
|
||
class MoneySerializerModuleFactory : AvroSerializerModuleFactory { | ||
override fun invoke(): SerializersModule = SerializersModule { | ||
contextual(convertedType, MoneySerializer()) | ||
} | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
lib/logical-types/src/main/kotlin/bankaccount/conversions/MoneyLogicalTypeFactory.kt
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
lib/logical-types/src/main/kotlin/bankaccount/conversions/MoneySerializer.kt
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
lib/logical-types/src/main/kotlin/bankaccount/conversions/MoneySerializerModule.kt
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
...es/src/main/kotlin/io/toolisticon/avro/kotlin/logicaltypes/AbstractAvroLogicalTypeBase.kt
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
...gical-types/src/main/kotlin/io/toolisticon/avro/kotlin/logicaltypes/AbstractConversion.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
...al-types/src/main/kotlin/io/toolisticon/avro/kotlin/logicaltypes/AvroLogicalTypeHolder.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.