8000 feat(serialization): add toObjectNode extension function for String by Ahoo-Wang · Pull Request #1461 · Ahoo-Wang/Wow · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(serialization): add toObjectNode extension function for String #1461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
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 @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.JavaType
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.ObjectNode
import com.fasterxml.jackson.module.kotlin.registerKotlinModule

object JsonSerializer : ObjectMapper() {
Expand Down Expand Up @@ -47,6 +48,10 @@ fun <T : JsonNode> String.toJsonNode(): T {
return JsonSerializer.readTree(this) as T
}

fun String.toObjectNode(): ObjectNode {
return toJsonNode()
}

fun <T> String.toObject(objectType: JavaType): T {
return JsonSerializer.readValue(this, objectType)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ internal class JsonSerializerTest {
)
val mockEventJson = mockEvent.toJsonString()
val mutableDomainEventRecord =
mockEventJson.toJsonNode<ObjectNode>().toDomainEventRecord().toMutableDomainEventRecord()
mockEventJson.toObjectNode().toDomainEventRecord().toMutableDomainEventRecord()
mutableDomainEventRecord.bodyType = "NotFoundClass"
val failedDomainEvent = mutableDomainEventRecord.actual.toJsonString().toObject<DomainEvent<Any>>()
assertThat(failedDomainEvent, instanceOf(JsonDomainEvent::class.java))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@

package me.ahoo.wow.serialization.event

import com.fasterxml.jackson.databind.node.ObjectNode
import me.ahoo.wow.api.Identifier
import me.ahoo.wow.id.generateGlobalId
import me.ahoo.wow.serialization.toJsonNode
import me.ahoo.wow.serialization.toJsonString
import me.ahoo.wow.serialization.toObjectNode
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class StateJsonRecordTest {
@Test
fun toState() {
val state = MockState()
val stateNode = state.toJsonString().toJsonNode<ObjectNode>()
val stateNode = state.toJsonString().toObjectNode()
val stateJsonRecord = StateJsonRecord(stateNode)
assertThat(stateJsonRecord.state<MockState>()).isEqualTo(state)
assertThat(stateJsonRecord.actual).isEqualTo(stateNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import me.ahoo.wow.serialization.event.FlatEventStreamRecord
import me.ahoo.wow.serialization.event.toEventStreamRecord
import me.ahoo.wow.serialization.toJsonNode
import me.ahoo.wow.serialization.toJsonString
import me.ahoo.wow.serialization.toObjectNode
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

Expand Down Expand Up @@ -110,7 +111,7 @@ class R2dbcEventStore(
id = id,
rawAggregateId = aggregateId,
ownerId = ownerId,
header = header.toJsonNode() as ObjectNode,
header = header.toObjectNode(),
body = body.toJsonNode(),
commandId = commandId,
requestId = requestId,
Expand Down
Loading
0