I'm trying to convert a HashMap of elements into a JSON string. I'm using the method used in this link.
val elementsNew: HashMap<String, Element> = HashMap(elements)
val type = Types.newParameterizedType(Map::class.java, String::class.java, Element::class.java)
var json: String = builder.adapter(type).toJson(elementsNew)
But this gives the following error
Error:(236, 40) Type inference failed: Not enough information to infer parameter T in fun adapter(p0: Type!): JsonAdapter! Please specify it explicitly.
Can any one tell me where's the fault? Is it because of Kotlin?
JsonAdapter<Object>(wouldn't be able to use that for yourMap<String, Element>type). Kotlin forces you to provide the parameterizing arguments, so you can see the mistake sooner. - Eric Cochran