-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix env value not being deserialized into string (#634)
* fix: fix env value not being transformed to string * docs(changeset): Fixed 'value' in actuator environment response not being transformable to string * Fixes * Remove unused import
- Loading branch information
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@krud-dev/ostara-main": patch | ||
--- | ||
|
||
Fixed 'value' in actuator environment response not being transformable to string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
daemon/src/main/kotlin/dev/krud/boost/daemon/jackson/ToStringDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.krud.boost.daemon.jackson | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.JsonNode | ||
|
||
/** | ||
* Deserialize a property value to a string, even if it's a number or boolean. | ||
*/ | ||
class ToStringDeserializer : JsonDeserializer<String>() { | ||
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): String { | ||
val node = p.codec.readTree<JsonNode>(p) | ||
return node.toString() | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
daemon/src/test/kotlin/dev/krud/boost/daemon/actuator/model/EnvActuatorResponseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dev.krud.boost.daemon.actuator.model | ||
|
||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import org.junit.jupiter.api.Test | ||
import strikt.api.expect | ||
import strikt.assertions.isEqualTo | ||
|
||
class EnvActuatorResponseTest { | ||
private val objectMapper = jacksonObjectMapper() | ||
|
||
@Test | ||
fun `response should deserialize non-string value as string`() { | ||
val json = """ | ||
{ | ||
"propertySources": [ | ||
{ | ||
"name": "source", | ||
"properties": { | ||
"some.value": { | ||
"value": {} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
""".trimIndent() | ||
|
||
val response = objectMapper.readValue(json, EnvActuatorResponse::class.java) | ||
expect { | ||
that(response.propertySources[0].properties!!["some.value"]!!.value).isEqualTo("{}") | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
daemon/src/test/kotlin/dev/krud/boost/daemon/jackson/ToStringDeserializerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.krud.boost.daemon.jackson | ||
|
||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import org.junit.jupiter.api.Test | ||
import strikt.api.expectThat | ||
import strikt.assertions.isEqualTo | ||
|
||
class ToStringDeserializerTest { | ||
private val objectMapper = jacksonObjectMapper() | ||
private val deserializer = ToStringDeserializer() | ||
|
||
@Test | ||
fun `ToStringDeserializer should return stringified object value`() { | ||
val parser = objectMapper.factory.createParser("{}") | ||
val result = deserializer.deserialize( | ||
parser, | ||
objectMapper.deserializationContext, | ||
) | ||
expectThat(result).isEqualTo("{}") | ||
} | ||
} |