Skip to content

Instantly share code, notes, and snippets.

@appsoluut
Created May 21, 2018 10:31
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 appsoluut/a8b32bc574d393e4d81474637c71a8f1 to your computer and use it in GitHub Desktop.
Save appsoluut/a8b32bc574d393e4d81474637c71a8f1 to your computer and use it in GitHub Desktop.
Retrofit article block example
RuntimeTypeAdapterFactory<Block> articleBlockFactory = RuntimeTypeAdapterFactory.of(Block.class, "type")
.registerSubtype(TextBlock.class, "text")
.registerSubtype(ImageBlock.class, "image")
.registerSubtype(VideoBlock.class, "video");
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
.registerTypeAdapterFactory(AutoValueTypeAdapterFactory.create())
.registerTypeAdapterFactory(articleBlockFactory)
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.example.com/")
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment