json of "rates":{"AAA":5.023852,"BBB":77.682521}
At first I did everything manually, in AsyncTask got json , parsed it into my class
class ModelData { private String name; private Double value; ModelData(String name, Double value) { this.name = name; this.value = value; } } and I sqLite the json response itself in the sqLite database. After all List<ModelDate> me in sqLite not to write. Here is another sub-question: do I understand correctly that in order to save an object in sqLite we create a json that repeats this object and save quietly as a string in the database. And there is ORMLite often heard, but now I think that it is needed to store objects in the database. As she does, I don’t know, she can also create json automatically and store it)
And then I decided to implement retrofit 2 (finally it should be) and naturally this is the loss of some flexibility and here’s the problem: my answer is parsed
@SerializedName("rates") @Expose private List<ModelData> ratesList; But how can I save this ratesList to sqLite . I understand that I can somehow convert and save this sheet to Json, but when reading from the database, I will have to parse again, and this parser code is even though I already have one.
This is what I would like: in the POJO model, to have separate and parsed fields and the raw json itself (what kind of annotation is needed to get json entirely? Or what is needed) And also be able to parse the json obtained from the database with the same class POJO model.
I think this is not a bad example of how retrofit 2 and sqLite together deprived of flexibility and for a small project turned out to be redundant and benefit from them only if the project grows.
UPD1 I understood that the interface to rest api can be configured to accept raw json, like this:
@GET("{date}") Call<JsonObject> getData(@Path("date") String date, @Query("access_key") String accessKey, @Query("base") String base); But how can I use the POJO model for this JsonObject later to parse it with a Gson converter added to the retrofit. This is the very thing that I did not understand in this library, where and what method is generally involved in parsing. At what point the converter is connected, maybe somewhere already at the level of okhttp3 ... In general, I was tired of stirring up this library