Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class ValueOrCompletionSerializer(
override fun read(readContext: ReadContext): ValueOrCompletion<*> {
return when (Type.entries[readContext.readByte().toInt()]) {
Type.VALUE -> {
val value = readContext.readRef() as Any
val value = readContext.readRef()
ValueOrCompletion.Value(value)
}
Type.COMPLETION -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ internal class ValueOrCompletionDeserializer :
?: throw JsonMappingException.from(p, "Missing type field for ValueOrCompletion")
return when (type) {
"value" -> {
val value =
node.get("value")?.let { p.codec.treeToValue(it, Any::class.java) }
val valueNode =
node.get("value")
?: throw JsonMappingException.from(p, "Missing value field for value type")
val value = if (valueNode.isNull) null else p.codec.treeToValue(valueNode, Any::class.java)
ValueOrCompletion.Value(value)
}
"completion" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ internal class ValueOrCompletionDeserializer :
?: throw DatabindException.from(p, "Missing type field for ValueOrCompletion")
return when (type) {
"value" -> {
val value =
node.get("value")?.let { ctxt.readTreeAsValue(it, Any::class.java) }
val valueNode =
node.get("value")
?: throw DatabindException.from(p, "Missing value field for value type")
val value = if (valueNode.isNull) null else ctxt.readTreeAsValue(valueNode, Any::class.java)
ValueOrCompletion.Value(value)
}
"completion" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class ValueOrCompletionSerializationTest :
deserialized shouldBe event
}

test("Value (null)") {
val event = ValueOrCompletion.Value<String?>(null)
val bytes = fory.serialize(event)
val deserialized = fory.deserialize(bytes)
deserialized shouldBe event
}

test("Completion") {
val event = ValueOrCompletion.Completion(null)
val bytes = fory.serialize(event)
Expand Down Expand Up @@ -92,7 +99,7 @@ class ValueOrCompletionSerializationTest :
val bytes = foryNoType.serialize(event)
val deserialized = foryNoType.deserialize(bytes) as ValueOrCompletion.Completion
deserialized.throwable.shouldBeInstanceOf<RuntimeException>()
deserialized.throwable?.message shouldBe "aah"
deserialized.throwable.message shouldBe "aah"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class ValueOrCompletionSerializationTest :
deserialized shouldBe event
}

test("Value (null)") {
val event: ValueOrCompletion<String?> = ValueOrCompletion.Value(null)
val json = mapper.writeValueAsString(event)
val deserialized =
mapper.readValue(json, object : TypeReference<ValueOrCompletion<String?>>() {})
deserialized shouldBe event
}

test("Completion (null)") {
val event: ValueOrCompletion<String> = ValueOrCompletion.Completion(null)
val json = mapper.writeValueAsString(event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class ValueOrCompletionSerializationTest :
deserialized shouldBe event
}

test("Value (null)") {
val event: ValueOrCompletion<String?> = ValueOrCompletion.Value(null)
val json = mapper.writeValueAsString(event)
val deserialized =
mapper.readValue(json, object : TypeReference<ValueOrCompletion<String?>>() {})
deserialized shouldBe event
}

test("Completion (null)") {
val event: ValueOrCompletion<String> = ValueOrCompletion.Completion(null)
val json = mapper.writeValueAsString(event)
Expand Down
Loading