4

enter image description here

The IDE is highlighting the those serialization imports as unresolved. But when run the app I am getting the result here.

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    Log.d("myTag",Model("venky").toJson()) //I am getting in logcat {"mod":"venky"}
}

}

It's working but showing error.

  • Have you tried adding `import kotlinx.serialization.Serializable`? It may be IDE problem – Phil Dukhov Jan 12 '22 at 14:37
  • Yeah I tried, it's not importing. It's showing me error – Venkatesh Paithireddy Jan 13 '22 at 03:23
  • Why are you both adding the serialization by `plugin` block and by the `classpath`? As far as I can see from [the documentation](https://github.com/Kotlin/kotlinx.serialization#gradle), you're mixing two approaches here. – Artyom Degtyarev Jan 13 '22 at 07:06
  • Yeah, I know that. At the start I only added plugin. It's not worked. Then I also added classpath. – Venkatesh Paithireddy Jan 13 '22 at 07:25
  • What IDE and plugins versions do you have here? It feels like there were similar reports in Kotlin issue tracker some time ago, but I cannot compare them with your case without the versions' info. – Artyom Degtyarev Jan 13 '22 at 13:45
  • I am using Android Studio Bumblebee | 2021.1.1 RC 1 Build #AI-211.7628.21.2111.8005941, built on December 16, 2021 Runtime version: 11.0.11+9-b60-7590822 amd64 VM: OpenJDK 64-Bit Server VM by Oracle Corporation – Venkatesh Paithireddy Jan 22 '22 at 04:47
  • provide your serialization dependency and plugin version please, your serialization dependency in commonMain? – Vadim Eksler Mar 16 '22 at 07:11
  • @ArtyomDegtyarev Could you share those reports? I now face the same issues, happened after upgrading to kotlin 1.6.21 from 1.4 and all the others with it (gradle, agp, compose) including serialization to 1.3.3 – Majkeee May 22 '22 at 16:46

1 Answers1

0

First, add library "org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.4.1" from maven to your project(Intelli IDEA menu: File/ProjectStructure). Then, follow the instruction https://kotlinlang.org/docs/serialization.html#example-json-serialization

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 22 '22 at 00:28