infinum / kotlin-jsonapix

JsonApiX is an Android, annotation processor library that was made to transform regular Kotlin classes into their JSON API representations, with the ability to serialize or deserialize them to or from strings.
Apache License 2.0
38 stars 9 forks source link

Cannot import TypeAdapterFactory #55

Closed Jonathan5579 closed 9 months ago

Jonathan5579 commented 1 year ago

I'm trying to assemble an example project, followed the imports in the readme but I'm getting a unresolved reference for TypeAdapterFactory. Searching in the projects files found the import "import com.infinum.jsonapix.TypeAdapterFactory" to then use the TypeAdapterFactory().getListAdapter(), but I'm not being able to import it. I'm not getting any Sync error, I think I'm not adding the kapt compiler pluging correctly and thus the jsonapix:processor is not being imported.

The code that I'm trying to run is this, from the Readme:

import com.infinum.jsonapix.TypeAdapterFactory

fun JsonApiFunApp(
    inputJsonString: String
){
    // Gets adapter for a single instance of Person
    val adapterr: TypeAdapter<Person>
    val adapter = TypeAdapterFactory().getAdapter(Person::class)

    // Gets adapter for a list of Person instances
    val listAdapter = TypeAdapterFactory().getListAdapter(Person::class)

    //adapter.convertToString(person) // Produces JSON API String from a Person instance
    adapter.convertFromString(inputJsonString) // Produces Person instance from JSON API String

    //listAdapter.convertToString(person) // Produces JSON API String from a Person list
    listAdapter.convertFromString(inputJsonString) // Produces Person list from JSON API String
}

This is what I've mofidied from the graddle files:

build.graddle:app

this is my build.graddle:app. I added the last three Id's in plugins and the first five implementations.

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id "kotlinx-serialization"
    id "kotlin-kapt"
    id "kotlin-android"
}

android {
    namespace 'com.example.jsonapixtutorial'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.jsonapixtutorial"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.2.0'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {
    // Serialization API. Check the docs link above for newer versions
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
    // Json API X
    implementation("com.infinum.jsonapix:core:1.0.0-beta02")
    kapt ("com.infinum.jsonapix:processor:1.0.0-beta02")
    // Optional: For Retrofit support
    implementation("com.infinum.jsonapix:retrofit:1.0.0-beta02")
    // Optional: Custom lint tool checker
    implementation("com.infinum.jsonapix:lint:1.0.0-beta02")

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.1'
    implementation "androidx.compose.ui:ui:$compose_ui_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
    implementation 'androidx.compose.material:material:1.2.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
}

build.graddle:project

In the build.graddle:project I added the dependencies in the buildscript, and the last two plugin ids.

buildscript {
    ext {
        compose_ui_version = '1.2.0'
    }
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-serialization:1.6.0")
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
    id 'org.jetbrains.kotlin.plugin.serialization' version '1.6.0'  apply true
    id 'org.jetbrains.kotlin.kapt' version '1.9.10' apply true
}

settings.graddle project

Lastly this is my settings.graddle project, the mavenCentral module was already included.

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "JsonApiX Tutorial"
include ':app'
thisAAY commented 1 year ago

Hey @Jonathan5579 ,

Thanks for pointing this out. I'll dive into the TypeAdapterFactory import and the kapt integration issue. I'll circle back once I've had a closer look.

Cheers!

thisAAY commented 10 months ago

Can you try to reproduce this with the new release 1.0.0?

nelsonzacharia commented 8 months ago

error still the same even release 1.0.0.0

e: file:///Users/xxxx/projects/android/VibaruaApp/app/src/main/java/tz/yy/xxx/vibarua/di/AppModule.kt:5:29 Unresolved reference: TypeAdapterFactor

On Tue, Jan 30, 2024 at 6:59 PM Ahmed Ali @.***> wrote:

Closed #55 https://github.com/infinum/kotlin-jsonapix/issues/55 as completed.

— Reply to this email directly, view it on GitHub https://github.com/infinum/kotlin-jsonapix/issues/55#event-11644007474, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABULXNH25CDA2E37OEUAWTDYREKFHAVCNFSM6AAAAAA6MIZE4CVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJRGY2DIMBQG42DONA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- nelson zacharia mscomputer and mobile phone : +255 (0) 713 127 045 my cv : nelsonzacharia.freetzi.com web : mscomputer.freetzi.com

thisAAY commented 8 months ago

Hey @nelsonzacharia

Can you provide us with a sample project with your case, so we can try it?

nelsonzacharia commented 8 months ago

Sure, no problem. I'm trying to connect an Android application to an existing Laravel JSON API server that also has a web interface built with JavaScript. I'm attempting to use the same endpoints for both interfaces.

attached are files from my android project

On Thu, Feb 29, 2024 at 7:46 PM Ahmed Ali @.***> wrote:

Hey @nelsonzacharia https://github.com/nelsonzacharia

Can you provide us with a sample project with your case, so we can try it?

— Reply to this email directly, view it on GitHub https://github.com/infinum/kotlin-jsonapix/issues/55#issuecomment-1971544033, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABULXNHYS4PXCQQK2MVVRDTYV5NQBAVCNFSM6AAAAAA6MIZE4CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZRGU2DIMBTGM . You are receiving this because you were mentioned.Message ID: @.***>

-- nelson zacharia mscomputer and mobile phone : +255 (0) 713 127 045 my cv : nelsonzacharia.freetzi.com web : mscomputer.freetzi.com

nelsonzacharia commented 8 months ago

any recommendation

On Thu, Feb 29, 2024 at 8:55 PM Nelson Zacharia @.***> wrote:

Sure, no problem. I'm trying to connect an Android application to an existing Laravel JSON API server that also has a web interface built with JavaScript. I'm attempting to use the same endpoints for both interfaces.

attached are files from my android project

On Thu, Feb 29, 2024 at 7:46 PM Ahmed Ali @.***> wrote:

Hey @nelsonzacharia https://github.com/nelsonzacharia

Can you provide us with a sample project with your case, so we can try it?

— Reply to this email directly, view it on GitHub https://github.com/infinum/kotlin-jsonapix/issues/55#issuecomment-1971544033, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABULXNHYS4PXCQQK2MVVRDTYV5NQBAVCNFSM6AAAAAA6MIZE4CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZRGU2DIMBTGM . You are receiving this because you were mentioned.Message ID: @.***>

-- nelson zacharia mscomputer and mobile phone : +255 (0) 713 127 045 my cv : nelsonzacharia.freetzi.com web : mscomputer.freetzi.com

-- nelson zacharia mscomputer and mobile phone : +255 (0) 713 127 045 my cv : nelsonzacharia.freetzi.com web : mscomputer.freetzi.com

DrakslerT commented 8 months ago

Hi @nelsonzacharia , we changed the TypeAdapterFactory class to contain only one generic function for returning both the single instance of a class and a list instance. So the TypeAdapterFactory().getListAdapter function does not exist anymore.

You can use it like this now:

Gets adapter for a single instance of Person val adapter = TypeAdapterFactory().getAdapter(PersonModel::class)

Gets adapter for a list of Person instances val listAdapter = TypeAdapterFactory().getAdapter(PersonList::class)

Was that your problem? If not, please provide a sample, we cannot see any files in your previous messages.