You are currently viewing Serializer for class is not found

Serializer for class is not found

Hi,

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 androidx.appcompat.app.AppCompatActivity 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{com.example.android.poc/com.example.android.poc.MainActivity}: 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 'com.android.tools.build:gradle:3.6.4' 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 } 

app

apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 29 buildToolsVersion "29.0.3" defaultConfig { applicationId "com.example.android.poc" minSdkVersion 19 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } 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]