Skip to content

Commit

Permalink
Added serializer for java.util.currency and typeAlias
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-pixel committed Aug 15, 2024
1 parent e38fd79 commit e9688f3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.ks3.java.time.LocalDateTimeAsStringSerializer
import io.ks3.java.time.LocalTimeAsStringSerializer
import io.ks3.java.time.OffsetDateTimeAsStringSerializer
import io.ks3.java.time.YearMonthAsStringSerializer
import io.ks3.java.util.CurrencySerializer
import io.ks3.java.util.LocaleSerializer
import io.ks3.java.util.UuidSerializer
import kotlinx.serialization.Serializable
Expand All @@ -24,6 +25,7 @@ import java.time.LocalDateTime
import java.time.LocalTime
import java.time.OffsetDateTime
import java.time.YearMonth
import java.util.Currency
import java.util.Locale
import java.util.UUID

Expand Down Expand Up @@ -78,3 +80,7 @@ typealias LocaleAsString =
typealias UuidAsString =
@Serializable(with = UuidSerializer::class)
UUID

typealias CurrencyAsString =
@Serializable(with = CurrencySerializer::class)
Currency
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.ks3.java.util

import io.ks3.standard.stringSerializer
import kotlinx.serialization.KSerializer
import java.util.Currency

object CurrencySerializer : KSerializer<Currency> by stringSerializer(Currency::getInstance)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.ks3.java.util

import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.arbitrary.map
import io.kotest.property.arbitrary.of
import io.ks3.test.generateSerializerTests
import kotlinx.serialization.json.Json
import java.util.Currency

class CurrencySerializerTest :
FreeSpec(
{
include(
generateSerializerTests(
CurrencySerializer,
Arb.of(Currency.getAvailableCurrencies()).map { it },
),
)
"sample" {
Json.encodeToString(CurrencySerializer, Currency.getInstance("AUD")) shouldBe "\"AUD\""
}
},
)

0 comments on commit e9688f3

Please sign in to comment.