Skip to content

Instantly share code, notes, and snippets.

@miensol
Created December 29, 2015 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miensol/e4e5fed9c36a75feb3cc to your computer and use it in GitHub Desktop.
Save miensol/e4e5fed9c36a75feb3cc to your computer and use it in GitHub Desktop.
public class RetrofitTest {
@Test
public void configure() throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.registerModule(new JodaModule());
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://httpbin.org")
.addConverterFactory(JacksonConverterFactory.create(mapper))
.client(new OkHttpClient())
.build();
final TestService service = retrofit.create(TestService.class);
final Call<Object> call = service.post(new TestMessage());
final Response<Object> result = call.execute();
assertThat(result, notNullValue());
}
public interface TestService {
@POST("/post")
Call<Object> post(@Body TestMessage message);
}
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NON_PRIVATE)
public static class TestMessage {
DateTime now = new DateTime();
LocalDate today = new LocalDate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment