Currently, GSON deserialization and retrofitting using GsonConverterFactory modifications:
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(new TypeToken<Map<Book, Collection<Author>>>(){}.getType(), new BooksDeserializer(context));
Gson gson = gsonBuilder.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
BookService service = retrofit.create(BookService.class);
Response<Map<Book, Collection<Author>>> response = service.getBooks().execute();
I would like to use JacksonConverterFactory, which is provided by modification? I would have to provide this to Jackson's cartographer. Is there a way to provide type information to this mapper, as was the case with GSON?
SimpleModule simpleModule = new SimpleModule();
mapper.registerModule(simpleModule);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(JacksonConverterFactory.create(mapper))
.build();
BookService service = retrofit.create(BookService.class);
Response<Map<Book, Collection<Author>>> response = service.getBooks().execute();
Looking specifically at TODO, can I say that the mapper uses this deserializer?
public class BooksDeserializer extends JsonDeserializer<Map<Book, Collection<Author>>> {
@Override
public Map<Book, Collection<Author>> deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
// deserialize here
}
}
source
share