我有一个HATEOAS(HAL) REST服务并设法与下面的代码交谈(使用halarious作为转换引擎)但是当我尝试合并转换器(stallone和stallone2)时,应用程序将总是拿起第一个转换器,而不是适合于响应类型的那个当然会导致错误.
我怎么能避免只在小型细节中有所不同的重复改造?
public interface Stallone {
@GET("/discovery")
Call<DiscoveryResponse> discover();
@POST()
Call<LoginResponse> login(@Url String url, @Body LoginRequest secret);
}
Run Code Online (Sandbox Code Playgroud)
public static void main(String... args) throws IOException {
// Initialize a converter for each supported (return) type
final Stallone stallone = new Retrofit.Builder()
.baseUrl(BASE)
.addConverterFactory(HALConverterFactory.create(DiscoveryResponse.class))
.build().create(Stallone.class);
final Stallone stallone2 = new Retrofit.Builder()
.baseUrl(BASE)
.addConverterFactory(HALConverterFactory.create(LoginResponse.class))
.build().create(Stallone.class);
// Follow the HAL links
Response<DiscoveryResponse> response = stallone.discover().execute();
System.out.println(response.code() + " " + response.message());
Assert.assertNotNull(response.body());
String …Run Code Online (Sandbox Code Playgroud)