Search before asking
Version
fory-json-kotlin 1.7.3
OS: Windows 11 25H2
Jdk 26.0.2.1
Kotlin 2.4.20
Component(s)
Java, Other
Minimal reproduce step
Result wrapper class:
data class Rt<T>(val flag: Boolean, val data: T? = null, val msg: String? = null)
fun <T> success(data: T): Rt<T> = Rt(true, data)
When using AbstractHttpMessageConverter, an error is reported: ForyJsonException: Unresolved Kotlin JSON type parameter 0
@Configuration
class WebConfig : WebMvcConfigurer {
@get:Bean
val foryJson: ForyJson = ForyJsonKotlin.builder().registerMixin<WithDetailMixin>().writeLongAsString(true)
.defaultPropertyInclusion(NON_EMPTY).build()
override fun configureMessageConverters(builder: HttpMessageConverters.ServerBuilder) {
builder.withJsonConverter(
object : AbstractHttpMessageConverter<Any>(APPLICATION_JSON) {
override fun supports(clazz: Class<*>): Boolean = true
override fun readInternal(clazz: Class<out Any>, inputMessage: HttpInputMessage): Any =
foryJson.fromJson(inputMessage.body.readAllBytes(), clazz)
override fun writeInternal(t: Any, outputMessage: HttpOutputMessage) =
foryJson.writeJsonTo(t, outputMessage.body)
})
}
}
When using AbstractGenericHttpMessageConverter, an error is reported: ForyJsonException: Platform-typed Kotlin JSON occurrence java.util.List<com.reggie.entity.Employee> is unsupported
override fun configureMessageConverters(builder: HttpMessageConverters.ServerBuilder) {
builder.withJsonConverter(
object : AbstractGenericHttpMessageConverter<Any>(APPLICATION_JSON) {
override fun supports(clazz: Class<*>): Boolean = true
override fun readInternal(clazz: Class<out Any>, inputMessage: HttpInputMessage): Any =
foryJson.fromJson(inputMessage.body.readAllBytes(), clazz)
override fun writeInternal(t: Any, type: Type?, outputMessage: HttpOutputMessage) =
foryJson.writeJsonTo(t, TypeRef.of(type), outputMessage.body)
override fun read(type: Type, contextClass: Class<*>?, inputMessage: HttpInputMessage): Any =
foryJson.fromJson(inputMessage.body.readAllBytes(), TypeRef.of(type))
})
In the subclass methods of HttpMessageConverter, I don't know how to use jsonTypeRef<T>().
However, using only ForyJson for construction can achieve normal serialization.
What did you expect to see?
Serialize Rt<List> to JSON.
What did you see instead?
Constructed only using ForyJson.
@get:Bean
val foryJson: ForyJson = ForyJson.builder().registerMixin<WithDetailMixin>().writeLongAsString(true)
.defaultPropertyInclusion(NON_EMPTY).build()
Anything Else?
No response
Are you willing to submit a PR?
Search before asking
Version
fory-json-kotlin 1.7.3
OS: Windows 11 25H2
Jdk 26.0.2.1
Kotlin 2.4.20
Component(s)
Java, Other
Minimal reproduce step
Result wrapper class:
When using AbstractHttpMessageConverter, an error is reported:
ForyJsonException: Unresolved Kotlin JSON type parameter 0When using AbstractGenericHttpMessageConverter, an error is reported:
ForyJsonException: Platform-typed Kotlin JSON occurrence java.util.List<com.reggie.entity.Employee> is unsupportedIn the subclass methods of HttpMessageConverter, I don't know how to use
jsonTypeRef<T>().However, using only ForyJson for construction can achieve normal serialization.
What did you expect to see?
Serialize Rt<List> to JSON.
What did you see instead?
Constructed only using ForyJson.
Anything Else?
No response
Are you willing to submit a PR?