There is a json file with geopoints ArrayList - "geopoint": [76.8958,43.2775]. In Realm you cannot store an ArrayList, for this I created a separate model for it:
Model - GeopointResponse:
public class GeopointResponse extends RealmObject { private float lat; private float lng; public float getLat() { return lat; } public void setLat(float lat) { this.lat = lat; } public float getLng() { return lng; } public void setLng(float lng) { this.lng = lng; } } Here I tried to write Deserialize:
public class GeopointDeserializer implements JsonDeserializer<GeopointResponse>, JsonSerializer<GeopointResponse> { @Override public GeopointResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Float lat = json.getAsJsonPrimitive().getAsFloat(); Float lng = json.getAsJsonPrimitive().getAsFloat(); GeopointResponse eventGeopoints = new GeopointResponse(); eventGeopoints.setLat(lat); eventGeopoints.setLng(lng); return eventGeopoints; } @Override public JsonElement serialize(GeopointResponse src, Type typeOfSrc, JsonSerializationContext context) { return null; } } I do not know how to write Deserialize & Serialize for this json of the form: "geopoint": [76.8958,43.2775]. Please help.
Json:
{ "id": "583bc78233f2763f927ad731", "interests": [ { "id": "583bc77d33f2763f927ad474", "parent": null, "local_cities": [], "title": "Изобразительное искусство", "is_global": true, "is_active": true }, { "id": "583bc77d33f2763f927ad476", "parent": null, "local_cities": [], "title": "Современное искусство", "is_global": true, "is_active": true } ], "city": { "id": "583bc77e33f2763f927ad495", "country_name": "Казахстан", "is_active": true, "name": "Алматы", "geopoint": [ 76.8958, 43.2775 ] }, "currency": { "id": "583bcfd633f276475e4746cf", "name": "Kazakhstani tenge" }, "author": { "id": "583bc77e33f2763f927ad497", "fn": "happerala@happapp.info" }, "start_datetime": "2015-11-12T00:00:00", "end_datetime": "2015-12-15T00:00:00", "is_upvoted": true, "is_in_favourites": false, "images": [ { "id": "583bc78233f2763f927ad732", "path": "/uploads/media/583bc78233f2763f927ad731/91adc85f338512b89a18e8528601aa211449650928.jpg", "color": "#595959" } ], "date_created": "2016-11-28T05:58:26.080000", "date_edited": "2016-11-28T05:58:26.080000", "title": "Персональная выставка Паоло Пиби", "description": "В Esentai Gallery продолжает свою работу персональная выставка молодого итальянского художника Паоло Пиби Fake Golden Age (\"Фальшивый Золотой век\").\r\n\r\nРаботы, представленные на выставке объединяют две вещи. Первая – узнаваемый авторский стиль: постоянное обращение к двум визуальным и тематическим планам, один из которых скрывает другой, отвлекает от него внимание, но именно скрытый план выступает источником первого, питает его и на границе между ними рождается мираж, поглощающий зрителя, выводяший его в пространство вне времени. Вторая – нарочитая высокая цитатность представленных работ: какие-то угадываются легко, какие-то то требуют напряжения – художник предлагает зрителю погрузиться в контекст живописи 20 века, сравнить её с современной, взглянуть на обе критически, и в конце концов – вступить в культурный диалог с самим автором, угадать его собственное отношение к источникам вдохновения – от пиетета до тонкой иронии.", "language": "en", "type": 0, "status": 1, "min_price": null, "max_price": null, "address": "Esentai Gallery, ТРЦ Esentai Mall, пр. Аль-Фараби 77/8", "place_name": null, "geopoint": null, "phones": [ "+7 (727) 330-88-77" ], "email": null, "web_site": "http://www.esentaimall.com/", "votes_num": 1, "close_on_start": false, "registration_link": null, "min_age": 0, "max_age": 200 }