# Kotlin doesn't play nicely with Jackson if the property name contains "is"

**URL:** <https://discuss.kotlinlang.org/t/kotlin-doesnt-play-nicely-with-jackson-if-the-property-name-contains-is/5798>\
**Category:** Support\
**Created:** [December 13, 2017, 10:32am UTC](https://discuss.kotlinlang.org/t/kotlin-doesnt-play-nicely-with-jackson-if-the-property-name-contains-is/5798 "2017-12-13T10:32:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![legezam](https://avatars.discourse-cdn.com/v4/letter/l/8e7dd6/32.png) [@legezam](https://discuss.kotlinlang.org/u/legezam)\
**Post date:** [December 13, 2017, 10:32am UTC](https://discuss.kotlinlang.org/t/kotlin-doesnt-play-nicely-with-jackson-if-the-property-name-contains-is/5798/1 "2017-12-13T10:32:07Z")

</div>

Hello

I am using kotlin 1.20 and jackson 2.9.0.

The following code snippet:

```
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. 🙂

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![whaph](https://avatars.discourse-cdn.com/v4/letter/w/f9ae1b/32.png) [@whaph](https://discuss.kotlinlang.org/u/whaph)\
**Post date:** [December 13, 2017, 12:15pm UTC](https://discuss.kotlinlang.org/t/kotlin-doesnt-play-nicely-with-jackson-if-the-property-name-contains-is/5798/2 "2017-12-13T12:15:48Z")

</div>

Maybe try annotating it with @JvmName(“isDirectory”)

[https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#handling-signature-clashes-with-jvmname](https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#handling-signature-clashes-with-jvmname)

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.

---

<div class="post-metadata">

**Author:** ![whaph](https://avatars.discourse-cdn.com/v4/letter/w/f9ae1b/32.png) [@whaph](https://discuss.kotlinlang.org/u/whaph)\
**Post date:** [December 13, 2017, 12:32pm UTC](https://discuss.kotlinlang.org/t/kotlin-doesnt-play-nicely-with-jackson-if-the-property-name-contains-is/5798/3 "2017-12-13T12:32:38Z")

</div>

Something like this should do the trick, I guess:

class MyResponse(directory: String){  
val isDirectory : String  
@JvmName(“isDirectory”) get() = field

```
init {
    isDirectory = directory
}

```

}

---

<div class="post-metadata">

**Author:** ![bastman](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@bastman](https://discuss.kotlinlang.org/u/bastman)\
**Post date:** [December 14, 2017, 8:50am UTC](https://discuss.kotlinlang.org/t/kotlin-doesnt-play-nicely-with-jackson-if-the-property-name-contains-is/5798/4 "2017-12-14T08:50:19Z")

</div>

Just annotate with @get:JsonProperty(“isDirectory”), e.g.:

data class MyResponse(@get:JsonProperty(“isDirectory”) val isDirectory: String)

See this example: [learn-spring-kotlin/EchoController.kt at master · bastman/learn-spring-kotlin · GitHub](https://github.com/bastman/learn-spring-kotlin/blob/master/src/main/kotlin/com/example/demo/api/echo/EchoController.kt)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![legezam](https://avatars.discourse-cdn.com/v4/letter/l/8e7dd6/32.png) [@legezam](https://discuss.kotlinlang.org/u/legezam)\
**Post date:** [December 14, 2017, 4:33pm UTC](https://discuss.kotlinlang.org/t/kotlin-doesnt-play-nicely-with-jackson-if-the-property-name-contains-is/5798/5 "2017-12-14T16:33:33Z")

</div>

Thank you!
