Skip to content

Commit

Permalink
Added serializer for java.util.currency and typeAlias (#143)
Browse files Browse the repository at this point in the history
* Added serializer and typeAlias for java.util.currency

* added example to MD, ran apiDump
  • Loading branch information
markus-pixel authored Oct 8, 2024
1 parent 505cf02 commit f2ec0f5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/jdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
| AtomicBoolean | AtomicBooleanSerializer | `true` |
| AtomicLong | AtomicLongSerializer | `22` |
| Locale | LocaleSerializer | `"en_US"` |
| Currency | CurrencySerializer | `"AUD"` |
9 changes: 9 additions & 0 deletions ks3-jdk/api/ks3-jdk.api
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ public final class io/ks3/java/util/AtomicLongSerializer : kotlinx/serialization
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/util/concurrent/atomic/AtomicLong;)V
}

public final class io/ks3/java/util/CurrencySerializer : kotlinx/serialization/KSerializer {
public static final field INSTANCE Lio/ks3/java/util/CurrencySerializer;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/util/Currency;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/util/Currency;)V
}

public final class io/ks3/java/util/LocaleSerializer : kotlinx/serialization/KSerializer {
public static final field INSTANCE Lio/ks3/java/util/LocaleSerializer;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
Expand Down
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 f2ec0f5

Please sign in to comment.