android 无法解析SerializedName

mhd8tkvw  于 2022-11-20  发布在  Android
关注(0)|答案(9)|浏览(303)

我做了一个Bean类,但是当我运行它的时候,这个类出现了错误。我不知道如何修复它。请帮助我。

Error:(7, 8) error: cannot find symbol class SerializedNameError:Execution failed for task ':app:compileDebugJavaWithJavac'.

这是建筑。

apply plugin: 'com.android.application'android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.example.administrator.Myappliction"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}}   dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'com.android.support:design:23.1.1'
compile files('libs/gson_1.7.jar')
compile files('libs/gson-2.2.4.jar')
compile "com.google.android.gms:play-services:8.3.0"}
iih3973s

iih3973s1#

只要加上implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
在您的Gradle文件(应用程序)中

qoefvg9y

qoefvg9y2#

在您的模型中:

import com.google.gson.annotations.SerializedName;

在build.gradel中添加gson和converter-gson

dependencies {
.
.
 implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
 implementation 'com.google.code.gson:gson:2.6.2'
}
rxztt3cl

rxztt3cl3#

我面临着同样的问题。终于解决了。我使用了两个改造gson转换器和谷歌gson转换器。我删除了谷歌gson转换器,并继续改造gson转换器,这解决了我的问题。
我保留了这个:implementation 'com.squareup.retrofit2:converter-gson:2.9.0'并删除了以下内容:implementation 'com.google.code.gson:gson:2.8.8'

vlf7wbxs

vlf7wbxs4#

再次同步gradle.build文件解决了我的问题。

o4hqfura

o4hqfura5#

将gson库更新为

implementation 'com.google.code.gson:gson:2.8.8'
o8x7eapl

o8x7eapl6#

您可以使用翻新2:converter-gson

implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

然后在你的课上

import com.google.gson.annotations.SerializedName

data class DataClassName(
    @SerializedName("user")
    val userId: String,
    @SerializedName("bike")
    val bikeId: String,
)
kzipqqlq

kzipqqlq7#

这个错误或警告通常在你使用需要导入和添加到依赖项的东西时出现:

Cannot resolve SerializedName

将其添加到gradle应用文件的依赖项下,如下所示:

dependencies {

implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

}

dependencies {

implementation 'com.google.code.gson:gson:2.8.8'

}

现在将其导入到java类中,如下所示:例如:

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
ndh0cuux

ndh0cuux8#

只需更新您的gson依赖项。添加以下两行即可解决问题

implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
   implementation 'com.google.code.gson:gson:2.8.8'
4sup72z8

4sup72z89#

将GSON依赖项添加到Gradle文件和模型中后,请确保已将GSON依赖项更新为最新版本。

相关问题