Skip to content

Commit

Permalink
microtype serialization/deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Sep 22, 2024
1 parent 2dd03af commit fad09f8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/src/test/kotlin/http/HttpClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class HttpClientTest : AbstractTest() {
val responseLog = verifyLog("http.response", Severity.ERROR)
responseLog.message shouldBe "Received 409 for GET /test-endpoint"
responseLog.keyValuePairs["responseCode"] shouldBe 409
responseLog.keyValuePairs["clientErrorCode"] shouldBe "oh.dear"
responseLog.keyValuePairs["clientErrorCode"] shouldBe ClientErrorCode("oh.dear")
responseLog.keyValuePairs["clientErrorMessage"] shouldBe "a bid already exists"
}

Expand Down
1 change: 1 addition & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ ktfmt { kotlinLangStyle() }

dependencies {
implementation("javax.activation:activation:1.1.1")
implementation("com.fasterxml.jackson.core:jackson-databind:2.16.1")
testImplementation(project(":test-core"))
}
25 changes: 25 additions & 0 deletions core/src/main/kotlin/types/StringMicrotype.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package types

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.JsonSerializer
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize

@JsonSerialize(using = StringMicrotypeSerializer::class)
@JsonDeserialize(using = StringMicrotypeDeserializer::class)
open class StringMicrotype(val value: String) {
override fun equals(other: Any?) =
other is StringMicrotype && this.javaClass == other.javaClass && this.value == other.value
Expand All @@ -8,3 +19,17 @@ open class StringMicrotype(val value: String) {

override fun toString(): String = value
}

class StringMicrotypeSerializer : JsonSerializer<StringMicrotype>() {
override fun serialize(
var1: StringMicrotype,
gen: JsonGenerator,
serializers: SerializerProvider
) {
gen.writeString(var1.value)
}
}

class StringMicrotypeDeserializer : JsonDeserializer<StringMicrotype>() {
override fun deserialize(p0: JsonParser, p1: DeserializationContext) = StringMicrotype(p0.text)
}

0 comments on commit fad09f8

Please sign in to comment.