1
我使用翻新來調用REST服務。 REST服務返回一個JSON消息。 Java響應對象具有空字段值。使用'retrofit'庫響應具有空字段
設置代碼:
Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
.create();
RestAdapter restAdapter = new RestAdapter.Builder()
.setConverter(new GsonConverter(gson))
.setEndpoint(myEndpoint).build();
restAdapter.setLogLevel(LogLevel.FULL);
SomeService someService = restAdapter
.create(SomeService.class);
服務接口:
public interface SomeService {
@POST("/firstParam/{firstParam}/secondParam/{secondParam}")
MyResponse callService(@Path("firstParam") String firstParam,
@Path("secondParam") String secondParam, @Body MyRequest request);
}
的響應POJO的:
class MyResponse {
private String paramOne;
private String paramTwo;
private String action;
private String status;
//getters and setters
}
但是,當我打電話:
MyResponse response = someService.callService("one","two",request);
響應中的字段仍然爲空。
我不得不使用自定義的JsonDeserializer來讓它工作,但我認爲這是標準的東西,它不應該需要JsonDeserializer。
你可以建議一種方法,使我無法使用JsonDeserializer嗎?
它可能會更容易幫助你,如果我們能找到一些示例響應JSON ... –
@大衛。 mihola在此感謝{ 「paramOne」:「456」, 「paramTwo」:「123」, 「action」:「actionOne」, 「status」:「success」 } – jakstack