List of shared objects as request body in modification 2 and Gson

This is the first time I am trying to modify 2 as part of the global refactoring of my application.

My application stores data of different codes that it reads from sensors. Each measure has common functions, so I created a parent class Measure (which is not abstract) and several subclasses for each data type that I need. For example, I created a subclass of TemperatureMeasure.

I have access to the public API, which I cannot change to send the measures that I collect in my application.

Using a modification (2.0 beta), I declared the interface using this method:

@POST("/bdd/measure/send/{measureType}/{sensorId}")
Call<APIResponse> sendFludiaRaw(@Path("site") String siteId, @Path("measureType") String measureType, @Path("sensor") String sensorId, @Body List<? extends Measure> measures);

My plan was to be able to call this method by providing a list of objects that extend the Measure class. I am using the Gson converter as a serializer. When I call this method - for example, with a list of TemperatureMeasure objects - the created JSON objects include only members of the Measure class, but none of the members of TemperatureMeasure.

What would be the best solution to eliminate this?

, , / Gson. , Measure. , Gson, JSON String, Retrofit. , , - .

, switch -?

+4

Source: https://habr.com/ru/post/1622105/


All Articles