Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.taxipixi.entity.json;
- import com.taxipixi.entity.MapCoordinates;
- import com.taxipixi.entity.Place;
- import org.json.JSONException;
- import org.json.JSONObject;
- public class PlaceJsonParser implements JsonParser<Place> {
- public static final String ID = "id";
- public static final String ADDRESS = "address";
- public static final String LATITUDE = "latitude";
- public static final String LONGITUDE = "longitude";
- public Place parse(JSONObject object) throws JSONException {
- Place place = null ;
- if(!object.isNull(LATITUDE) && !object.isNull(LONGITUDE)) {
- place = new Place();
- place.setId(object.getLong(ID));
- place.setDescription(object.getString(ADDRESS));
- MapCoordinates coords = new MapCoordinates();
- //MK: lat lng getting rounded off to integer
- coords.setLatitude(object.getDouble(LATITUDE));
- coords.setLongitude(object.getDouble(LONGITUDE));
- place.setMapCoordinates(coords);
- }
- return place;
- }
- public JSONObject asJson(Place place) throws JSONException {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put(ADDRESS, place.getDescription());
- jsonObject.put(LATITUDE, place.getLatitude());
- jsonObject.put(LONGITUDE, place.getLongitude());
- return jsonObject;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment