I am trying to use Kotlin Jackson extensions to do JSON conversions in my code. But for some reason, I am getting a syntax error when trying to use the readValue(File)
function.
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.13.3'
---
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
...
private val objectMapper = jacksonObjectMapper()
...
val factionList: List<Faction> = objectMapper.readValue<List<Faction>>(
File(javaClass.classLoader.getResource("data/factions.json").file))
The error I get from the compiler is:
None of the following functions can be called with the arguments supplied.
readValue(JsonParser!, ResolvedType!)
...
[it lists all the valid function signatures ...]
However, none of the extension functions seem to be showing up in that list. If I click on the function and hit Cmd-B
in IntelliJ, I am seeing the readValue(File)
method in the extensions code.
I am confused why the function is not being found by the compiler.
CodePudding user response:
You're most likely missing the following import:
import com.fasterxml.jackson.module.kotlin.readValue
Forgot this a few times myself.