我有一个简单的网络通话,使用Jackson进行转换,设置如下
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("*****")
.addConverterFactory(JacksonConverterFactory.create(new
ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)))
.build();
apiService = retrofit.create(APIService.class);
和
使用
获取BGControl对象列表public interface APIService {
@GET("endpoint/{ID}")
Call<List<BGControl>> getBGControlData(@Path("ID") int patientId, @Query("start") String startDate, @Query("end") String endDate);
}
以下是BGControl类,
@JsonIgnoreProperties(ignoreUnknown = true)
public class BGControl {
String Activity;
String Glucose_mg_dL;
String Glucose_mmol_L;
String Timestamp;
String Classification;
String ReadingType;
int intervals = 0;
public BGControl() {
}
public BGControl(String activity, String glucose_mg_dL, String glucose_mmol_L, String timestamp, String classification, String readingType) {
Activity = activity;
Glucose_mg_dL = glucose_mg_dL;
Glucose_mmol_L = glucose_mmol_L;
Timestamp = timestamp;
Classification = classification;
ReadingType = readingType;
}
public void setActivity(String activity) {
Activity = activity;
}
public void setGlucose_mg_dL(String glucose_mg_dL) {
Glucose_mg_dL = glucose_mg_dL;
}
public void setGlucose_mmol_L(String glucose_mmol_L) {
Glucose_mmol_L = glucose_mmol_L;
}
public void setTimestamp(String timestamp) {
Timestamp = timestamp;
}
public void setClassification(String classification) {
Classification = classification;
}
public void setReadingType(String readingType) {
ReadingType = readingType;
}
public String getActivity() {
return Activity;
}
public String getGlucose_mg_dL() {
return Glucose_mg_dL;
}
public String getGlucose_mmol_L() {
return Glucose_mmol_L;
}
public String getTimestamp() {
return Timestamp;
}
public String getClassification() {
return Classification;
}
public String getReadingType() {
return ReadingType;
}
public int getIntervals() {
return intervals;
}
public void setIntervals(int intervals) {
this.intervals = intervals;
}
@Override
public String toString() {
return "BGControl{" +
"Activity='" + Activity + '\'' +
", Glucose_mg_dL='" + Glucose_mg_dL + '\'' +
", Glucose_mmol_L='" + Glucose_mmol_L + '\'' +
", Timestamp='" + Timestamp + '\'' +
", Classification='" + Classification + '\'' +
", ReadingType='" + ReadingType + '\'' +
'}';
}
}
以下是网络电话消费者代码
final Call<List<BGControl>> graphDataCall = NetworkManager.getInstance().getAPIService().getBGControlData(13614, startDate, endDate);
graphDataCall.enqueue(new Callback<List<BGControl>>() {
@Override
public void onResponse(Call<List<BGControl>> call, Response<List<BGControl>> response) {
List<BGControl> bgControlList = response.body();
if (bgControlList.size() > 0) {
}
}
@Override
public void onFailure(Call<List<BGControl>> call, Throwable t)
{
graphDataCall.cancel();
}
});
然而,问题是,当我通过Android工作室运行它时,它会在设备中安装APK,我检查它是否正确映射了响应并因此更新了UI(我已经渲染了多个图形!带有此响应!)(工作室运行assembleProdDebug命令)。但是当我在设备中使用命令行安装相同的apk &#34; adb install -r ***。apk&#34;回复无效。
这很奇怪,我发送这个apk到客户端:(在手动安装和验证这个apk之前,现在它是一个问题。
如果您遇到类似问题,请提出解决方案。
答案 0 :(得分:1)
您可能已经使用proguard来缩小更改变量名称的代码。
生成apk时,您可以尝试从minifyEnabled
文件设置build.gradle
false。
如果您想将proguard与Retrofit一起使用,请检查此问题的答案: