forked from Cookies_Github_mirror/AquaDX
[+] More extensions
This commit is contained in:
@@ -32,10 +32,10 @@ val JACKSON = jacksonObjectMapper().apply {
|
||||
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE);
|
||||
}
|
||||
inline fun <reified T> ObjectMapper.readValue(str: Str) = readValue(str, T::class.java)
|
||||
inline fun <reified T> ObjectMapper.parse(str: Str) = readValue(str, T::class.java)
|
||||
// TODO: https://stackoverflow.com/q/78197784/7346633
|
||||
inline fun <reified T> Str.parseJackson() = if (contains("null")) {
|
||||
val map = JACKSON.readValue<MutableMap<String, Any>>(this)
|
||||
val map = JACKSON.parse<MutableMap<String, Any>>(this)
|
||||
JACKSON.convertValue(map.recursiveNotNull(), T::class.java)
|
||||
}
|
||||
else JACKSON.readValue(this, T::class.java)
|
||||
@@ -50,4 +50,13 @@ val JSON = Json {
|
||||
namingStrategy = JsonNamingStrategy.SnakeCase
|
||||
explicitNulls = false
|
||||
coerceInputValues = true
|
||||
}
|
||||
}
|
||||
|
||||
// Bean for default jackson object mapper
|
||||
//@Configuration
|
||||
//class JacksonConfig {
|
||||
// @Bean
|
||||
// fun objectMapper(): ObjectMapper {
|
||||
// return JACKSON
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user