data class MyResponse(var isDirectory: String)
fun main(args: Array<String>) {
val mapper = ObjectMapper().registerModule(KotlinModule())
println( mapper.writerWithDefaultPrettyPrinter().writeValueAsString(MyResponse("hello")))
}
prints out this output: { }
If i change the name of the property:
data class MyResponse(var directory: String)
fun main(args: Array<String>) {
val mapper = ObjectMapper().registerModule(KotlinModule())
println( mapper.writerWithDefaultPrettyPrinter().writeValueAsString(MyResponse("hello")))
}
The output strangely becomes okay:
{
"directory" : "hello"
}
Basically, if i remove the “is” prefix from the property, it is okay. It also doesn’t work with “isFile”
I am not sure whether it is with kotlin or with jackson, but something is definitely wrong here.
That way your identifier in your src code is like you want it to be and should work like you expect it.
var isDirectory : String will be compiled to getIsDirectory()/setIsDirectory() so jackson thinks the name of the property is isDirectory instead of just directory.