Skip to content

Commit

Permalink
refactor: JsonCodec fail on unknown & missing property (#145)
Browse files Browse the repository at this point in the history
* refactor: JsonCodec fail on Unknown property

* refactor: JsonCodec Fail On Missing properties

* docs: version 0.4.5 0> 0.4.6
  • Loading branch information
devxb authored Jul 7, 2024
1 parent a11eb05 commit d9a9b33
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<br>

![version 0.4.5](https://img.shields.io/badge/version-0.4.5-black?labelColor=black&style=flat-square) ![jdk 17](https://img.shields.io/badge/minimum_jdk-17-orange?labelColor=black&style=flat-square) ![load-test](https://img.shields.io/badge/load%20test%2010%2C000%2C000-success-brightgreen?labelColor=black&style=flat-square)
![version 0.4.6](https://img.shields.io/badge/version-0.4.6-black?labelColor=black&style=flat-square) ![jdk 17](https://img.shields.io/badge/minimum_jdk-17-orange?labelColor=black&style=flat-square) ![load-test](https://img.shields.io/badge/load%20test%2010%2C000%2C000-success-brightgreen?labelColor=black&style=flat-square)
![redis--stream](https://img.shields.io/badge/-redis--stream-da2020?style=flat-square&logo=Redis&logoColor=white)

**TPS(6,000)** on my Macbook air m2(default options). _[link](#Test1-TPS)_
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kotlin.code.style=official

### Project ###
group=org.rooftopmsa
version=0.4.5
version=0.4.6
compatibility=17

### Sonarcloud ###
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/org/rooftop/netx/redis/RedisSagaConfigurer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.rooftop.netx.redis
import com.fasterxml.jackson.annotation.JsonAutoDetect
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.PropertyAccessor
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.KotlinModule
Expand Down Expand Up @@ -123,6 +124,9 @@ class RedisSagaConfigurer(
.registerModule(ParameterNamesModule(JsonCreator.Mode.PROPERTIES))
.registerModule(KotlinModule.Builder().build())
.registerModule(JavaTimeModule())
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, true)
.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true)

@Bean
@ConditionalOnProperty(prefix = "netx", name = ["mode"], havingValue = "redis")
Expand Down
42 changes: 42 additions & 0 deletions src/test/kotlin/org/rooftop/netx/ground/GroudTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.rooftop.netx.ground

import com.fasterxml.jackson.annotation.JsonAutoDetect
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.PropertyAccessor
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule
import io.kotest.assertions.throwables.shouldThrowAny
import io.kotest.core.spec.style.StringSpec
import io.kotest.extensions.spring.SpringExtension
import org.rooftop.netx.meta.EnableSaga
import org.rooftop.netx.redis.RedisContainer
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource

@EnableSaga
@TestPropertySource("classpath:application.properties")
@ContextConfiguration(classes = [RedisContainer::class])
class GroudTest(
private val netxObjectMapper: ObjectMapper,
) : StringSpec({

extension(SpringExtension)

"ObjectMapper UnknownProperty Test" {
val request = "{ \"name\": \"xb\" }"

shouldThrowAny {
netxObjectMapper.readValue(request, Target::class.java)
}
}
}) {

data class Target(
val id: Long,
val name: String,
val isSuccess: Boolean,
)
}

0 comments on commit d9a9b33

Please sign in to comment.