Android 改装2.0/Jackson:无法识别的性能异常
我正在尝试对Jackson解析器使用改进2.0,但它不起作用。它不会将值映射到模型。这给了我一个例外: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:未识别的字段“total_count”(class models.GitResult),未标记为可忽略(3个已知属性:“UncompleteResults”、“items”、“totalcount”)Android 改装2.0/Jackson:无法识别的性能异常,android,json,jackson,retrofit2,Android,Json,Jackson,Retrofit2,我正在尝试对Jackson解析器使用改进2.0,但它不起作用。它不会将值映射到模型。这给了我一个例外: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:未识别的字段“total_count”(class models.GitResult),未标记为可忽略(3个已知属性:“UncompleteResults”、“items”、“totalcount”) 在[Source:buffer((缓冲区)(okio。GzipS
在[Source:buffer((缓冲区)(okio。GzipSource@2235992))).inputStream();行:1,列:21](通过引用链:models.GitResult[“total_count”]) 但在我的模型和json响应中,键值是相同的。 这就是模型:
private boolean incompleteResults;
private List<Item> items = new ArrayList<Item>();
private int totalcount;
项目模型也已正确制作。它适用于GsonConverterFactory
,但不适用于JacksonFactory
以下是我的客户端设置:
private static GitApiInterface gitApiInterface ;
private static String baseUrl = "https://api.github.com" ;
public static GitApiInterface getClient() {
if (gitApiInterface == null) {
OkHttpClient okClient = new OkHttpClient();
okClient.interceptors().add(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response response = chain.proceed(chain.request());
return response;
}
});
Retrofit client = new Retrofit.Builder()
.baseUrl(baseUrl)
.client(okClient)
.addConverterFactory(rest.JacksonConverterFactory.create())
.build();
gitApiInterface = client.create(GitApiInterface.class);
}
return gitApiInterface ;
}
还有我的格拉德尔依赖
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta4'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1'
compile 'com.squareup.retrofit:converter-jackson:2.0.0-beta1'
compile 'com.squareup.okhttp3:okhttp:3.0.0'
}
在json中,您有
总数
在java中,您有
总数
您应该使用相同的名称或使用@JsonProperty注释,如下所示:
@JsonProperty("total_count")
private int totalcount;
在json中,您有
总数
在java中,您有
总数
您应该使用相同的名称或使用@JsonProperty注释,如下所示:
@JsonProperty("total_count")
private int totalcount;
我注意到的第一件事是你把不同版本的改装和它的转换器弄混了。请注意不要在
compile'com.squareup.Refught2:converter jackson:2.0.0-beta4'
和compile'com.squareup.Refught2:Refught2:2.0.0-beta4'
中改装2。我注意到的第一件事是您混淆了不同版本的改装及其转换器。请注意不要在编译'com.squareup.infrant2:converter-jackson:2.0.0-beta4'
和编译'com.squareup.infrant2:infrant2.0-beta4'
中改装2。