1

What is the best way to cast my response from the server ?

  1. By directly assigning the response to the entity
Ex: authorityStatusWithWorkFlowEntity = response.body();

OR

  1. First Catching it as JsonElement OR JsonArray OR JsonObject and then converting it to specified entity?
Ex: lineEstimationEntity = new Gson().fromJson(response.body().getAsJsonObject(), new TypeToken<LineEstimationEntity>() {
                        }.getType());

In performance wise which is the best practice?

  • use a gson convertor and you can directly deal with data class/pojos. – Raghunandan Mar 20 '20 at 07:50
  • There are two ways of doing it. Firstly, you can do some pure work like using the response and serializing/deserializing it and getting the data out of it. Secondly, you can have good use of GSON with retrofit while you configure your retrofit `.addConverterFactory(GsonConverterFactory.create())` and down the line, you can go for either RxJava or Kotlin's flow API – Akshay Nandwana Mar 20 '20 at 07:57
  • @Raghunandan Which is the best practice in terms of performance? – Sandeep Karanam Mar 20 '20 at 09:05
  • @AkshayNandwana Which is the best practice in terms of performance? – Sandeep Karanam Mar 20 '20 at 09:10
  • @SandeepKulkarni I think POJO is the best for catch the response from server. Here is the further advantages. https://stackoverflow.com/a/14172743/7498057 – Komal Mar 20 '20 at 09:39
  • @SandeepKulkarni you get the json converted to pojo while using a gson convertor instead of manually parsing the json yourself. it is what most people do so there is not a lot to worry about performance – Raghunandan Mar 20 '20 at 11:46

0 Answers0