I have this json file as example:
[{"Type":"car","color":"black"},{"Type":"Motorcycle","color":"white"},....]
By using the Gson lib I need to separate it for differents classes.
I'm using the code below to read the file :
BufferedReader bufferedReader = new BufferedReader(new FileReader("v.json"));
And the code below to put it in a object:
Gson gson = new Gson();
List<vehicles> vehicles = gson.fromJson(bufferedReader, new TypeToken<List<Car>>() {}.getType());
My question is how can I check the "type":"car"
and add it to an Object Car and the "type":"motorcycle"
to an Object Motorcycle
The gson.fromJson code I'm using is adding all to an object Car.
Thanks