You are currently viewing Serializer for class is not found

Serializer for class is not found


I recently started playing with Kotlin, and I would like to use the Json serializer tool that is offered. Despite having setup my gradle env and followed the tutorials provided i encounter the following error with this code:

import import android.os.Bundle import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import kotlinx.serialization.Serializable @Serializable data class Project(val name: String, val language: String) fun main() { val data = Json.decodeFromString<Project>(""" {"name":"kotlinx.serialization","language":"Kotlin"} """) println(data) } class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) main() } }

 java.lang.RuntimeException: Unable to start activity ComponentInfo{}: kotlinx.serialization.SerializationException: Serializer for class 'Project' is not found.

Any idea on what I am missing ?

edit, gradles:

Project: buildscript { ext.kotlin_version = '1.4.10' repositories { google() jcenter() } dependencies { classpath '' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }


apply plugin: '' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 29 buildToolsVersion "29.0.3" defaultConfig { applicationId "" minSdkVersion 19 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1" }

submitted by /u/shtworld
[link] [comments]