Skip to content

Commit a03b664

Browse files
authored
fix: JsonCodec encode, decode private fields too (#134)
1 parent 25a600c commit a03b664

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/main/kotlin/org/rooftop/netx/redis/RedisSagaConfigurer.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.rooftop.netx.redis
22

3+
import com.fasterxml.jackson.annotation.JsonAutoDetect
34
import com.fasterxml.jackson.annotation.JsonCreator
5+
import com.fasterxml.jackson.annotation.PropertyAccessor
46
import com.fasterxml.jackson.databind.ObjectMapper
57
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
68
import com.fasterxml.jackson.module.kotlin.KotlinModule
@@ -116,7 +118,9 @@ class RedisSagaConfigurer(
116118
@Bean
117119
@ConditionalOnProperty(prefix = "netx", name = ["mode"], havingValue = "redis")
118120
internal fun netxObjectMapper(): ObjectMapper =
119-
ObjectMapper().registerModule(ParameterNamesModule(JsonCreator.Mode.PROPERTIES))
121+
ObjectMapper()
122+
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
123+
.registerModule(ParameterNamesModule(JsonCreator.Mode.PROPERTIES))
120124
.registerModule(KotlinModule.Builder().build())
121125
.registerModule(JavaTimeModule())
122126

src/test/kotlin/org/rooftop/netx/engine/OrchestratorConfigurer.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import reactor.core.publisher.Mono
1212
import java.time.Instant
1313

1414
@Configuration
15-
internal class OrchestratorConfigurer {
15+
internal class OrchestratorConfigurer(
16+
private val orchestratorFactory: OrchestratorFactory,
17+
) {
1618

1719
@Bean(name = ["numberOrchestrator"])
1820
fun numberOrchestrator(): Orchestrator<Int, Int> {
@@ -226,6 +228,15 @@ internal class OrchestratorConfigurer {
226228
})
227229
}
228230

231+
@Bean(name = ["privateFieldOrchestrator"])
232+
fun privateFieldOrchestrator(): Orchestrator<OrchestratorTest.Private, OrchestratorTest.Private> {
233+
return OrchestratorFactory.instance()
234+
.create<OrchestratorTest.Private>("privateFieldOrchestrator")
235+
.start({ it })
236+
.join({ it })
237+
.commit({ it })
238+
}
239+
229240
object PairOrchestrate :
230241
Orchestrate<Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>, Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>> {
231242
override fun orchestrate(request: Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>): Pair<OrchestratorTest.Foo, OrchestratorTest.Foo> {

src/test/kotlin/org/rooftop/netx/engine/OrchestratorTest.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.kotest.core.annotation.DisplayName
66
import io.kotest.core.spec.style.DescribeSpec
77
import io.kotest.matchers.equality.shouldBeEqualToComparingFields
88
import io.kotest.matchers.equals.shouldBeEqual
9+
import io.kotest.matchers.shouldBe
910
import org.rooftop.netx.api.Orchestrator
1011
import org.rooftop.netx.api.TypeReference
1112
import org.rooftop.netx.meta.EnableSaga
@@ -36,7 +37,8 @@ internal class OrchestratorTest(
3637
@Qualifier("contextOrchestrator") private val contextOrchestrator: Orchestrator<String, String>,
3738
@Qualifier("pairOrchestrator") private val pairOrchestrator: Orchestrator<String, Pair<Foo, Foo>>,
3839
@Qualifier("startWithContextOrchestrator") private val startWithContextOrchestrator: Orchestrator<String, String>,
39-
@Qualifier("fooContextOrchestrator") private val fooContextOrchestrator: Orchestrator<String, List<Foo>>
40+
@Qualifier("fooContextOrchestrator") private val fooContextOrchestrator: Orchestrator<String, List<Foo>>,
41+
private val privateOrchestrator: Orchestrator<Private, Private>,
4042
) : DescribeSpec({
4143

4244
describe("numberOrchestrator 구현채는") {
@@ -210,6 +212,19 @@ internal class OrchestratorTest(
210212
}
211213
}
212214
}
215+
216+
describe("privateFieldOrchestrator 구현채는") {
217+
context("saga 메소드가 호출되면,") {
218+
val private = Private("I'm private")
219+
220+
it("Private 필드가 포함된 객체를 반환한다.") {
221+
val result = privateOrchestrator.sagaSync(private)
222+
223+
result.isSuccess shouldBeEqual true
224+
result.decodeResultOrThrow(Private::class) shouldBeEqual private
225+
}
226+
}
227+
}
213228
}) {
214229
data class Home(
215230
val address: String,
@@ -228,6 +243,8 @@ internal class OrchestratorTest(
228243

229244
data class Foo(val name: String)
230245

246+
data class Private(private val name: String)
247+
231248
companion object {
232249
val rollbackOrchestratorResult = mutableListOf<String>()
233250
val upChainResult = mutableListOf<String>()

0 commit comments

Comments
 (0)