Android app returning inner arrays as [ ] or Array

2019-08-08 22:13发布

问题:

Hi I am new to Java and android and I'm trying to parse data from linked classes but I can not work out how to retrieve jsonObjects from some of the inner/nested JSONArrays?

I can retrieve objects from the outer JSONArray's but I can not see how to retrieve the nested JSONArray list objects from segments inner JSONArrays within the StorlineData class.

When I try to parse data from the inner/nested JSONArrays the response looks like this:

Thanks in advance for your help.

JSON (I am unable to get data from trackPointsData and PlacesData)

[
    {
        "date": "20121212",
        "summary": [
            {
                "activity": "walking",
                "group": "walking",
                "duration": 3333,
                "distance": 3333,
                "steps": 3333,
                "calories": 300
            },



        ],
        "segments": [
            {
                "type": "place",
                "startTime": "20121212T000000+0200",
                "endTime": "20121212T071430+0200",
                "place": {
                    "id": 1,
                    "type": "unknown",
                    "location": {
                        "lat": 55.55555,
                        "lon": 33.33333
                    }
                },
                "lastUpdate": "20130317T121143Z"
            },
            {
                "type": "move",
                "startTime": "20121212T071430+0200",
                "endTime": "20121212T074617+0200",
                "activities": [
                    {
                        "activity": "walking",
                        "group": "walking",
                        "manual": false,
                        "startTime": "20121212T071430+0200",
                        "endTime": "20121212T072732+0200",
                        "duration": 782,
                        "distance": 1251,
                        "steps": 1353,
                        "calories": 99,
                        "trackPoints": [
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T071430+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T072732+0200"
                            }
                        ]
                    },
                    {
                        "activity": "transport",
                        "group": "transport",
                        "manual": false,
                        "startTime": "20121212T072732+0200",
                        "endTime": "20121212T074616+0200",
                        "duration": 1124,
                        "distance": 8443,
                        "trackPoints": [
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T072732+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T074208+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T074617+0200"
                            }
                        ]
                    }
                ],
                "lastUpdate": "20130317T121143Z"
            },
            {
                "type": "place",
                "startTime": "20121212T074617+0200",
                "endTime": "20121212T100051+0200",
                "place": {
                    "id": 2,
                    "type": "unknown",
                    "location": {
                        "lat": 55.55555,
                        "lon": 33.33333
                    }
                },
                "activities": [
                    {
                        "activity": "walking_on_treadmill",
                        "group": "walking",
                        "manual": true,
                        "duration": 270,
                        "steps": 303,
                        "calories": 30,
                        "trackPoints": []
                    }
                ],
                "lastUpdate": "20130317T121143Z"
            },

            {
                "type": "place",
                "startTime": "20121212T100715+0200",
                "endTime": "20121212T110530+0200",
                "place": {
                    "id": 4,
                    "name": "test",
                    "type": "foursquare",
                    "foursquareId": "4df0fdb17d8ba370a011d24c",
                    "foursquareCategoryIds": ["4bf58dd8d48988d125941735"],
                    "location": {
                        "lat": 55.55555,
                        "lon": 33.33333
                    }
                },
                "activities": [
                    {
                        "activity": "walking",
                        "group": "walking",
                        "manual": false,
                        "startTime": "20121212T101215+0200",
                        "endTime": "20121212T101255+0200",
                        "duration": 40,
                        "distance": 18,
                        "steps": 37,
                        "calories": 99,
                        "trackPoints": [
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T101215+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T101255+0200"
                            }
                        ]
                    }
                ],
                "lastUpdate": "20130317T121143Z"
            },
            {
                "type": "move",
                "startTime": "20121212T110530+0200",
                "endTime": "20121212T111129+0200",
                "activities": [
                    {
                        "activity": "walking",
                        "group": "walking",
                        "manual": false,
                        "startTime": "20121212T110530+0200",
                        "endTime": "20121212T111128+0200",
                        "duration": 358,
                        "distance": 493,
                        "steps": 441,
                        "calories": 99,
                        "trackPoints": [
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T110531+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T110536+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T110947+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T111017+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T111129+0200"
                            }
                        ]
                    }
                ],
                "lastUpdate": "20130317T121143Z"
            },
            {
                "type": "place",
                "startTime": "20121212T111129+0200",
                "endTime": "20121212T153638+0200",
                "place": {
                    "id": 2,
                    "type": "unknown",
                    "location": {
                        "lat": 55.55555,
                        "lon": 33.33333
                    }
                },
                "activities": [
                    {
                        "activity": "zumba",
                        "manual": true,
                        "duration": 570,
                        "calories": 200,
                        "trackPoints": []
                    }
                ],
                "lastUpdate": "20130317T121143Z"
            },

            {
                "type": "place",
                "startTime": "20121212T160744+0200",
                "endTime": "20121212T232730+0200",
                "place": {
                    "id": 1,
                    "type": "unknown",
                    "location": {
                        "lat": 55.55555,
                        "lon": 33.33333
                    }
                },
                "lastUpdate": "20130317T121143Z"
            }
        ],
        "caloriesIdle": 1785,
        "lastUpdate": "20130317T121143Z"
    }
]

Main Activity:

...
    private MovesHandler<ArrayList<StorylineData>> storylineHandler = new MovesHandler<ArrayList<StorylineData>>() {
                @Override
                public void onSuccess(ArrayList<StorylineData> result) {
                    toggleProgress(false);
                    updateResponse(
...
                                + "-----------Segment 1-------\t"
                                + "StartTime:\t" + result.get(0).getSegments().get(0).getStartTime() + "\n"
                                + "             -Activities Array-\t" + "\n"
                                + "- StartTime:\t" +

 ...

                        + "-----------Segment 2-------\t" + "\n"
                        + "- TrackPoints :\t" + result.get(0).getTrackPoints()+ "\n"//====Array Add
                        + "- FoursquareId:\t" + result.get(0).getFoursquareId() + "\n"
                        + "- ACt:\t" + result.get(0).getActivities()+ "\n"
                            + "- Foursquare Id:\t" + result.get(0).getSegments().get(0).getPlace().getFoursquareId() + "\n"
                            + "- Foursquare Id:\t" + result.get(0).getFoursquareId() + "\n"
                            + "- Foursquare Category Ids:\t" + result.get(0).getSegments().get(0).getPlace().getFoursquareCategoryIds()+ "\n"
                            + "- Activities:\t" + result.get(0).getSegments().get(0).getActivities()+ "\n"
);

        }

...

StorylineData Class (I would like to retrieve jsonObjects from inner JSONArrays here in the storylineData class):

/**
 * Parse a {@link org.json.JSONObject} from storyline {@link org.json.JSONArray}, then return the corresponding {@link StorylineData} object.
 *
 * @param jsonObject : the storyline JSON object received from server
 * @return corresponding {@link StorylineData}
 */
public static StorylineData parse(JSONObject jsonObject) throws JSONException {
    if (jsonObject != null) {

        StorylineData storylineData = new StorylineData();

        storylineData.date = jsonObject.optString("date");
        storylineData.caloriesIdle = jsonObject.optInt("caloriesIdle");
        storylineData.lastUpdate = jsonObject.optString("lastUpdate");
        storylineData.summary = new ArrayList<>();
        storylineData.segments = new ArrayList<>();

        JSONArray summariesJsonArray = jsonObject.optJSONArray("summary");

        if (summariesJsonArray != null)
        for (int i = 0; i < summariesJsonArray.length(); i++) {

            JSONObject summaryJsonObject = summariesJsonArray.optJSONObject(i);

                    if (summaryJsonObject != null) {
                    summariesJsonArray.getJSONObject(i).getString("distance");

                        String group = summaryJsonObject.optString("group");

                        Integer distance = summaryJsonObject.optInt("distance");
                        storylineData.setDistance(distance);
...
                    storylineData.summary.add(SummaryData.parse(summaryJsonObject));

                        Log.d("StorylineDataCls \t sJo", summaryJsonObject.toString() + "Log\n");
                        System.out.println("print distance" + summariesJsonArray.getJSONObject(i).getString("distance"));       
                        System.out.println("print summary" + summaryJsonObject);

                }
            }

        JSONArray segmentsJsonArray = jsonObject.optJSONArray("segments");
        if (segmentsJsonArray != null) {

            for (int i = 0; i < segmentsJsonArray.length(); i++) {
                JSONObject segment = segmentsJsonArray.optJSONObject(i);

                if (segment != null) {

                    JSONArray activitiesJsonArray = segment.optJSONArray("activities");
                    if (activitiesJsonArray!=null) {

                        for (int j = 0; j < activitiesJsonArray.length(); j++) {
                            JSONObject trackPoints = activitiesJsonArray.optJSONObject(j);
                            if(trackPoints != null){
                        ...
                    storylineData.trackPoints.add(TrackPointsData.parse(trackPoints));
                                 }
                        }
                    }

            ..
                    Log.d("StorylineDataCls \t sSo", segment.toString());
                    System.out.println("print segment" + segment);
                    //System.out.println("print segments" + segments);
                    System.out.println("print segmentsJsonArray" + segmentsJsonArray);

                }
            }
        }


        return storylineData;
    }
    return null;


}

============PARSER METHODS IN LINKED CLASSES================

PlaceData Class:

/**
     * Parse a {@link org.json.JSONObject} of place, then return the corresponding {@link PlaceData} object.
     * @param jsonObject : the 'place' JSON object to parse
     * @return corresponding {@link PlaceData}
     */
    public static PlaceData parse(JSONObject jsonObject) {
        if (jsonObject != null) {
            PlaceData placeData = new PlaceData();

        placeData.id            = jsonObject.optString("id");
        placeData.name          = jsonObject.optString("name");
        placeData.type          = jsonObject.optString("type");
        placeData.foursquareId  = jsonObject.optString("foursquareId");

        JSONObject location = jsonObject.optJSONObject("location");
        if (location != null) {
            placeData.location = LocationData.parse(location);
        }

        JSONArray trackPointsJSONArray      = jsonObject.optJSONArray("foursquareCategoryIds");
        placeData.foursquareCategoryIds = new ArrayList<String>();
        if (trackPointsJSONArray != null) {
            for (int i = 0; i < trackPointsJSONArray.length(); i++) {
                String categoryId  = trackPointsJSONArray.optString(i);
                if (categoryId != null && categoryId.length() > 0) {

                    placeData.foursquareCategoryIds.add(categoryId);
                }
            }
        }


        return placeData;
    }
    return null;
}

}

LocationData Class:

/**
     * Parse a {@link org.json.JSONObject} from trackPoints {@link org.json.JSONArray}, then return the corresponding
     * {@link LocationData} object.
     * @param jsonObject : the 'trackPoint' JSON object to parse
     * @return corresponding {@link LocationData}
     */
    public static LocationData parse(JSONObject jsonObject) {
        if (jsonObject != null) {
                LocationData trackPointsData = new LocationData();
                trackPointsData.lat     = jsonObject.optString("lat");
                trackPointsData.lon     = jsonObject.optString("lon");


            return trackPointsData;
        }
        return null;
    }

}

TrackPointData Class:

/**
 * Parse a {@link org.json.JSONObject} from trackPoints {@link org.json.JSONArray}, then return the corresponding
 * {@link TrackPointsData} object.
 * @param jsonObject : the 'trackPoint' JSON object to parse
 * @return corresponding {@link TrackPointsData}
 */
public static TrackPointsData parse(JSONObject jsonObject) {
    if (jsonObject != null) {
            TrackPointsData trackPointsData = new TrackPointsData();
            trackPointsData.lat     = jsonObject.optString("lat");
            trackPointsData.lon     = jsonObject.optString("lon");
            trackPointsData.time    = jsonObject.optString("time");


            return trackPointsData;
    }
    return null;
}

}

ActivityData Class:

/**
     * Parse a {@link org.json.JSONObject} from activities {@link org.json.JSONArray}, then return the corresponding
     * {@link ActivityData} object.
     * @param jsonObject : the 'activity' JSON object to parse
     * @return corresponding {@link ActivityData}
     */
    public static ActivityData parse(JSONObject jsonObject) {
        if (jsonObject != null) {
            ActivityData activityData = new ActivityData();
                activityData.activity       = jsonObject.optString("activity");
                activityData.group          = jsonObject.optString("group");
                activityData.manual         = jsonObject.optString("manual");
                activityData.startTime      = jsonObject.optString("startTime");
                activityData.endTime        = jsonObject.optString("endTime");
                activityData.duration       = jsonObject.optInt("duration");
                activityData.distance       = jsonObject.optInt("distance");
                activityData.steps          = jsonObject.optInt("steps");
                activityData.calories       = jsonObject.optInt("calories");
            JSONArray trackPointsJSONArray      = jsonObject.optJSONArray("trackPoints");

                activityData.trackPoints = new ArrayList<TrackPointsData>();
                if (trackPointsJSONArray != null) {
                    for (int i = 0; i < trackPointsJSONArray.length(); i++) {
                        JSONObject summaryJsonObject = trackPointsJSONArray.optJSONObject(i);
                        if (summaryJsonObject != null) {



                            activityData.trackPoints.add(TrackPointsData.parse(summaryJsonObject));


                        }
                    }
                }



                return activityData;
        }
        return null;


    }


}

SegmentData Class:

/**
     * Parse a {@link org.json.JSONObject} from segments {@link org.json.JSONArray}, then return the corresponding {@link SegmentData} object.
     * @param jsonObject : the 'segment' JSON object to parse
     * @return corresponding {@link SegmentData}
     */
    public static SegmentData parse(JSONObject jsonObject) {
        if (jsonObject != null) {
            SegmentData segmentData = new SegmentData();
            segmentData.type        = jsonObject.optString("type");
            segmentData.startTime   = jsonObject.optString("startTime");
            segmentData.endTime     = jsonObject.optString("endTime");
            segmentData.lastUpdate  = jsonObject.optString("lastUpdate");
            segmentData.name    = jsonObject.optString("name");

            JSONArray activitiesJSONArray = jsonObject.optJSONArray("activities");
            segmentData.activities = new ArrayList<ActivityData>();
            if (activitiesJSONArray != null) {
                for (int i = 0; i < activitiesJSONArray.length(); i++) {
                    JSONObject activityJsonObject = activitiesJSONArray.optJSONObject(i);
                    if (activityJsonObject != null) {


                        placeData = (PlaceData) activityJsonObject.opt(String.valueOf(placeData));
                        segmentData.setPlace(placeData);



                        segmentData.activities.add(ActivityData.parse(activityJsonObject));
                    }
                }
            }

            JSONObject placeJsonObject = jsonObject.optJSONObject("place");
            if (placeJsonObject != null) {
                segmentData.place = PlaceData.parse(placeJsonObject);
            }

            return segmentData;
        }
        return null;
    }
}

SummaryData Class:

/**
     * Parse a {@link org.json.JSONObject} from summary {@link org.json.JSONArray}, then return the corresponding {@link SummaryData} object.
     * @param jsonObject : the 'summary' JSON object to parse
     * @return corresponding {@link SummaryData}
     */
    public static SummaryData parse(JSONObject jsonObject) {
        if (jsonObject != null) {
                SummaryData summary = new SummaryData();
                summary.activity        = jsonObject.optString("activity");
                summary.group           = jsonObject.optString("group");
                summary.duration        = jsonObject.optInt("duration");
                summary.distance        = jsonObject.optInt("distance");
                summary.steps           = jsonObject.optInt("steps");
                summary.calories        = jsonObject.optInt("calories");

            //Log.d("json", summary.toString());



            return summary;
        }
        return null;
    }
}

HTTPCall Class: ...

    public static void getDailyStorylineList(final MovesHandler<ArrayList<StorylineData>> handler,
                                             final String specificSummary,
                                             final String from,
                                             final String to,
                                             final String pastDays,
                                             final String updatedSince,
                                             final boolean needTrackPoints) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    /* Refresh access token if only AuthData.MOVES_REFRESHBEFORE days are there to expire current token */
                    AuthData.refreshAccessTokenIfNeeded();

                    /* Exchange the authorization code we obtained after login to get access token */
                    HashMap<String, String> nameValuePairs = new HashMap<String, String>();
                    nameValuePairs.put("access_token", AuthData.getAuthData().getAccessToken());

                   // if (specificSummary != null && specificSummary.length() > 0) nameValuePairs.put("specificSummary", specificSummary);//att

                    if (from != null && from.length() > 0) nameValuePairs.put("from", from);
                    if (to != null && to.length() > 0) nameValuePairs.put("to", to);
                    if (pastDays != null && pastDays.length() > 0) nameValuePairs.put("pastDays", pastDays);
                    if (updatedSince != null && updatedSince.length() > 0) nameValuePairs.put("updatedSince", updatedSince);
                    if (needTrackPoints) nameValuePairs.put("trackPoints", "true");


                    URL url     = new URL(MovesAPI.API_BASE + MovesAPI.API_PATH_STORYLINE + (specificSummary != null ? specificSummary : "") + "?" + Utilities.encodeUrl(nameValuePairs));
                    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                    urlConnection.setRequestMethod("GET");
                    urlConnection.setDoInput(true);
                    urlConnection.connect();

                    if (urlConnection.getResponseCode() != 200) {
                        /* All other HTTP errors from Moves will fall here */
                        handler.onFailure(getErrorStatus(Utilities.readStream(urlConnection.getErrorStream()), urlConnection.getResponseCode()), "Server not responded with success ("+ urlConnection.getResponseCode() +")");
                        return;
                    }

                    String response = Utilities.readStream(urlConnection.getInputStream());
                    Object object = new JSONTokener(response).nextValue();
                    if (object instanceof JSONArray) {
                        JSONArray jsonArray = (JSONArray) object;
                        ArrayList<StorylineData> storylineData = new ArrayList<StorylineData>();
                        if (jsonArray != null) {
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject storylineJsonObject = jsonArray.optJSONObject(i);
                                if (storylineJsonObject != null) {
                                    storylineData.add(StorylineData.parse(storylineJsonObject));
                                }
                            }
                        }
                        handler.onSuccess(storylineData);
                    } else {
                        handler.onFailure(MovesStatus.INVALID_RESPONSE, "Expected a JSONArray from server, but failed");
                    }

                } catch (Exception ex) {
                    ex.printStackTrace();
                    handler.onFailure(MovesStatus.UNEXPECTED_ERROR, "An unexpected error occured, please check logcat");
                }
            }
        }).start();
    }

MovesHandler Class

/**
 * This interface will act as a handler who notifies all success and failures
 * 
 *
 * @param <T> : A generic class, which probably will be the response type after success
 * @see MovesStatus
 */
public interface MovesHandler<T> {//T stands for generic type

    /**
     * Implement this method to get success notifications along with the result
     * @param result : Result of the operation completed with this handler
     */
    public void onSuccess(T result);

    /**
     * Implement this method to get failure notifications along with the {@link MovesStatus} code and a brief message
     * @param status : Status code of the failure
     * @param message : A brief message about the reason behind failure
     */
    public void onFailure(MovesStatus status, String message);
}

MovesAPI Class

 /**
     * Get daily storylines for user.
     * @see <a href="https://dev.moves-app.com/docs/api_storyline">Moves Developer Page for Daily Storyline</a>
     * @see SummaryListData
     * @param handler : An implemented {@link MovesHandler} with an {@link ArrayList} of {@link StorylineData}.
     * This handler will get notified when the request completes.
     * @param date : date in yyyyMMdd or yyyy-MM-dd format
     * @param updatedSince : [optional] if set, return only days which data has been updated since
     * given time stamp in ISO 8601 (yyyyMMdd’T’HHmmssZ) format, pass <code>null</code> if not required.
     * @param needTrackPoints : if true, the returned activities also include {@link TrackPointsData} information.
     * Including track points limits the query range to 7 days.
     */
    public static void getStoryline_SingleDay(MovesHandler<ArrayList<StorylineData>> handler, String date, String updatedSince, boolean needTrackPoints) {
        if (AuthData.isAuthenticated()) {
            HTTPCall.getDailyStorylineList(handler, "/" + date, null, null, null, updatedSince, needTrackPoints);
        } else {
            handler.onFailure(MovesStatus.NOT_AUTHENTICATED, "You are not yet authenticated with required scopes!");
        }
    }

SummaryListData Class:

public static SummaryListData parse(JSONObject jsonObject) {
        if (jsonObject != null) {
                SummaryListData summary = new SummaryListData();

                summary.date            = jsonObject.optString("date");
                summary.caloriesIdle    = jsonObject.optString("caloriesIdle");
                summary.lastUpdate      = jsonObject.optString("lastUpdate");
                summary.summaries       = new ArrayList<SummaryData>();

                JSONArray summariesJsonArray= jsonObject.optJSONArray("summary");
                if (summariesJsonArray != null) {
                    for (int i = 0; i < summariesJsonArray.length(); i++) {
                        JSONObject summaryJsonObject = summariesJsonArray.optJSONObject(i);
                        if (summaryJsonObject != null) {
                            summary.summaries.add(SummaryData.parse(summaryJsonObject));

                            Log.d("summaryHandler", summaryJsonObject.toString());


                        }
                    }
                }

                return summary;
        }
        return null;
    }


}

回答1:

Here is another way to solve your problem.

Follow this steps :

1) import Jackson library in your android project. How to import jackson library

2) Copy your json data and paste it in the text section http://jsonviewer.stack.hu/ and then click on the viewer tab.

3) Once the library is imported copy your JSON data and paste it in the edit text box Json2Schema

  • Set source type as JSON

  • Set annotation style as Jackson 2.x

  • Then just click preview
  • It will popup a window with all your boiler plate code, now copy this data in different classes in respective package e.g com.android.json.pojo
  • Change the name of the classes accordingly as some class names will be Example

4) Now wherever you are getting your json string from server parse using the following code.

RootElement rootElement = null;
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(Feature.AUTO_CLOSE_SOURCE, true);
// this line is very important
objectMapper.configure(

DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);

try {
        rootElement = objectMapper.readValue(result, RootElement.class);
    } catch (JsonParseException e) {
            e.printStackTrace();
    } catch (JsonMappingException e) {
            e.printStackTrace();
    }

RootElement class is nothing but the class which has json property same as the first elements for example

@JsonPropertyOrder({
"date",
"summary",
"segments",
"caloriesIdle",
"lastUpdate"
})

Your rootElement has the parsed data now.



回答2:

this is your valid json response

[
    {
        "date": "20121212",
        "summary": [
            {
                "activity": "walking",
                "group": "walking",
                "duration": 3333,
                "distance": 3333,
                "steps": 3333,
                "calories": 300
            }
        ],
        "segments": [
            {
                "type": "place",
                "startTime": "20121212T000000+0200",
                "endTime": "20121212T071430+0200",
                "place": {
                    "id": 1,
                    "type": "unknown",
                    "location": {
                        "lat": 55.55555,
                        "lon": 33.33333
                    }
                },
                "lastUpdate": "20130317T121143Z"
            },
            {
                "type": "move",
                "startTime": "20121212T071430+0200",
                "endTime": "20121212T074617+0200",
                "activities": [
                    {
                        "activity": "walking",
                        "group": "walking",
                        "manual": false,
                        "startTime": "20121212T071430+0200",
                        "endTime": "20121212T072732+0200",
                        "duration": 782,
                        "distance": 1251,
                        "steps": 1353,
                        "calories": 99,
                        "trackPoints": [
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T071430+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T072732+0200"
                            }
                        ]
                    },
                    {
                        "activity": "transport",
                        "group": "transport",
                        "manual": false,
                        "startTime": "20121212T072732+0200",
                        "endTime": "20121212T074616+0200",
                        "duration": 1124,
                        "distance": 8443,
                        "trackPoints": [
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T072732+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T074208+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T074617+0200"
                            }
                        ]
                    }
                ],
                "lastUpdate": "20130317T121143Z"
            },
            {
                "type": "place",
                "startTime": "20121212T074617+0200",
                "endTime": "20121212T100051+0200",
                "place": {
                    "id": 2,
                    "type": "unknown",
                    "location": {
                        "lat": 55.55555,
                        "lon": 33.33333
                    }
                },
                "activities": [
                    {
                        "activity": "walking_on_treadmill",
                        "group": "walking",
                        "manual": true,
                        "duration": 270,
                        "steps": 303,
                        "calories": 30,
                        "trackPoints": []
                    }
                ],
                "lastUpdate": "20130317T121143Z"
            },
            {
                "type": "place",
                "startTime": "20121212T100715+0200",
                "endTime": "20121212T110530+0200",
                "place": {
                    "id": 4,
                    "name": "test",
                    "type": "foursquare",
                    "foursquareId": "4df0fdb17d8ba370a011d24c",
                    "foursquareCategoryIds": [
                        "4bf58dd8d48988d125941735"
                    ],
                    "location": {
                        "lat": 55.55555,
                        "lon": 33.33333
                    }
                },
                "activities": [
                    {
                        "activity": "walking",
                        "group": "walking",
                        "manual": false,
                        "startTime": "20121212T101215+0200",
                        "endTime": "20121212T101255+0200",
                        "duration": 40,
                        "distance": 18,
                        "steps": 37,
                        "calories": 99,
                        "trackPoints": [
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T101215+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T101255+0200"
                            }
                        ]
                    }
                ],
                "lastUpdate": "20130317T121143Z"
            },
            {
                "type": "move",
                "startTime": "20121212T110530+0200",
                "endTime": "20121212T111129+0200",
                "activities": [
                    {
                        "activity": "walking",
                        "group": "walking",
                        "manual": false,
                        "startTime": "20121212T110530+0200",
                        "endTime": "20121212T111128+0200",
                        "duration": 358,
                        "distance": 493,
                        "steps": 441,
                        "calories": 99,
                        "trackPoints": [
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T110531+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T110536+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T110947+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T111017+0200"
                            },
                            {
                                "lat": 55.55555,
                                "lon": 33.33333,
                                "time": "20121212T111129+0200"
                            }
                        ]
                    }
                ],
                "lastUpdate": "20130317T121143Z"
            },
            {
                "type": "place",
                "startTime": "20121212T111129+0200",
                "endTime": "20121212T153638+0200",
                "place": {
                    "id": 2,
                    "type": "unknown",
                    "location": {
                        "lat": 55.55555,
                        "lon": 33.33333
                    }
                },
                "activities": [
                    {
                        "activity": "zumba",
                        "manual": true,
                        "duration": 570,
                        "calories": 200,
                        "trackPoints": []
                    }
                ],
                "lastUpdate": "20130317T121143Z"
            },
            {
                "type": "place",
                "startTime": "20121212T160744+0200",
                "endTime": "20121212T232730+0200",
                "place": {
                    "id": 1,
                    "type": "unknown",
                    "location": {
                        "lat": 55.55555,
                        "lon": 33.33333
                    }
                },
                "lastUpdate": "20130317T121143Z"
            }
        ],
        "caloriesIdle": 1785,
        "lastUpdate": "20130317T121143Z"
    }
]

And this are your POJO classes accordingly

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"activity",
"manual",
"duration",
"calories",
"trackPoints"
})
public class Activity {

@JsonProperty("activity")
private String activity;
@JsonProperty("manual")
private Boolean manual;
@JsonProperty("duration")
private Integer duration;
@JsonProperty("calories")
private Integer calories;
@JsonProperty("trackPoints")
private List<Object> trackPoints = new ArrayList<Object>();
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**
* 
* @return
* The activity
*/
@JsonProperty("activity")
public String getActivity() {
return activity;
}

/**
* 
* @param activity
* The activity
*/
@JsonProperty("activity")
public void setActivity(String activity) {
this.activity = activity;
}

/**
* 
* @return
* The manual
*/
@JsonProperty("manual")
public Boolean getManual() {
return manual;
}

/**
* 
* @param manual
* The manual
*/
@JsonProperty("manual")
public void setManual(Boolean manual) {
this.manual = manual;
}

/**
* 
* @return
* The duration
*/
@JsonProperty("duration")
public Integer getDuration() {
return duration;
}

/**
* 
* @param duration
* The duration
*/
@JsonProperty("duration")
public void setDuration(Integer duration) {
this.duration = duration;
}

/**
* 
* @return
* The calories
*/
@JsonProperty("calories")
public Integer getCalories() {
return calories;
}

/**
* 
* @param calories
* The calories
*/
@JsonProperty("calories")
public void setCalories(Integer calories) {
this.calories = calories;
}

/**
* 
* @return
* The trackPoints
*/
@JsonProperty("trackPoints")
public List<Object> getTrackPoints() {
return trackPoints;
}

/**
* 
* @param trackPoints
* The trackPoints
*/
@JsonProperty("trackPoints")
public void setTrackPoints(List<Object> trackPoints) {
this.trackPoints = trackPoints;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}

your location class

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"lat",
"lon"
})
public class Location {

@JsonProperty("lat")
private Double lat;
@JsonProperty("lon")
private Double lon;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**
* 
* @return
* The lat
*/
@JsonProperty("lat")
public Double getLat() {
return lat;
}

/**
* 
* @param lat
* The lat
*/
@JsonProperty("lat")
public void setLat(Double lat) {
this.lat = lat;
}

/**
* 
* @return
* The lon
*/
@JsonProperty("lon")
public Double getLon() {
return lon;
}

/**
* 
* @param lon
* The lon
*/
@JsonProperty("lon")
public void setLon(Double lon) {
this.lon = lon;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}

Your Place class

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"id",
"type",
"location"
})
public class Place {

@JsonProperty("id")
private Integer id;
@JsonProperty("type")
private String type;
@JsonProperty("location")
private Location location;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**
* 
* @return
* The id
*/
@JsonProperty("id")
public Integer getId() {
return id;
}

/**
* 
* @param id
* The id
*/
@JsonProperty("id")
public void setId(Integer id) {
this.id = id;
}

/**
* 
* @return
* The type
*/
@JsonProperty("type")
public String getType() {
return type;
}

/**
* 
* @param type
* The type
*/
@JsonProperty("type")
public void setType(String type) {
this.type = type;
}

/**
* 
* @return
* The location
*/
@JsonProperty("location")
public Location getLocation() {
return location;
}

/**
* 
* @param location
* The location
*/
@JsonProperty("location")
public void setLocation(Location location) {
this.location = location;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}

Your RootElement class

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"date",
"summary",
"segments",
"caloriesIdle",
"lastUpdate"
})
public class RootElement {

@JsonProperty("date")
private String date;
@JsonProperty("summary")
private List<Summary> summary = new ArrayList<Summary>();
@JsonProperty("segments")
private List<Segment> segments = new ArrayList<Segment>();
@JsonProperty("caloriesIdle")
private Integer caloriesIdle;
@JsonProperty("lastUpdate")
private String lastUpdate;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**
* 
* @return
* The date
*/
@JsonProperty("date")
public String getDate() {
return date;
}

/**
* 
* @param date
* The date
*/
@JsonProperty("date")
public void setDate(String date) {
this.date = date;
}

/**
* 
* @return
* The summary
*/
@JsonProperty("summary")
public List<Summary> getSummary() {
return summary;
}

/**
* 
* @param summary
* The summary
*/
@JsonProperty("summary")
public void setSummary(List<Summary> summary) {
this.summary = summary;
}

/**
* 
* @return
* The segments
*/
@JsonProperty("segments")
public List<Segment> getSegments() {
return segments;
}

/**
* 
* @param segments
* The segments
*/
@JsonProperty("segments")
public void setSegments(List<Segment> segments) {
this.segments = segments;
}

/**
* 
* @return
* The caloriesIdle
*/
@JsonProperty("caloriesIdle")
public Integer getCaloriesIdle() {
return caloriesIdle;
}

/**
* 
* @param caloriesIdle
* The caloriesIdle
*/
@JsonProperty("caloriesIdle")
public void setCaloriesIdle(Integer caloriesIdle) {
this.caloriesIdle = caloriesIdle;
}

/**
* 
* @return
* The lastUpdate
*/
@JsonProperty("lastUpdate")
public String getLastUpdate() {
return lastUpdate;
}

/**
* 
* @param lastUpdate
* The lastUpdate
*/
@JsonProperty("lastUpdate")
public void setLastUpdate(String lastUpdate) {
this.lastUpdate = lastUpdate;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}

Your Segment class

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"type",
"startTime",
"endTime",
"place",
"lastUpdate",
"activities"
})
public class Segment {

@JsonProperty("type")
private String type;
@JsonProperty("startTime")
private String startTime;
@JsonProperty("endTime")
private String endTime;
@JsonProperty("place")
private Place place;
@JsonProperty("lastUpdate")
private String lastUpdate;
@JsonProperty("activities")
private List<Activity> activities = new ArrayList<Activity>();
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**
* 
* @return
* The type
*/
@JsonProperty("type")
public String getType() {
return type;
}

/**
* 
* @param type
* The type
*/
@JsonProperty("type")
public void setType(String type) {
this.type = type;
}

/**
* 
* @return
* The startTime
*/
@JsonProperty("startTime")
public String getStartTime() {
return startTime;
}

/**
* 
* @param startTime
* The startTime
*/
@JsonProperty("startTime")
public void setStartTime(String startTime) {
this.startTime = startTime;
}

/**
* 
* @return
* The endTime
*/
@JsonProperty("endTime")
public String getEndTime() {
return endTime;
}

/**
* 
* @param endTime
* The endTime
*/
@JsonProperty("endTime")
public void setEndTime(String endTime) {
this.endTime = endTime;
}

/**
* 
* @return
* The place
*/
@JsonProperty("place")
public Place getPlace() {
return place;
}

/**
* 
* @param place
* The place
*/
@JsonProperty("place")
public void setPlace(Place place) {
this.place = place;
}

/**
* 
* @return
* The lastUpdate
*/
@JsonProperty("lastUpdate")
public String getLastUpdate() {
return lastUpdate;
}

/**
* 
* @param lastUpdate
* The lastUpdate
*/
@JsonProperty("lastUpdate")
public void setLastUpdate(String lastUpdate) {
this.lastUpdate = lastUpdate;
}

/**
* 
* @return
* The activities
*/
@JsonProperty("activities")
public List<Activity> getActivities() {
return activities;
}

/**
* 
* @param activities
* The activities
*/
@JsonProperty("activities")
public void setActivities(List<Activity> activities) {
this.activities = activities;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}

Your Summary Class

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"activity",
"group",
"duration",
"distance",
"steps",
"calories"
})
public class Summary {

@JsonProperty("activity")
private String activity;
@JsonProperty("group")
private String group;
@JsonProperty("duration")
private Integer duration;
@JsonProperty("distance")
private Integer distance;
@JsonProperty("steps")
private Integer steps;
@JsonProperty("calories")
private Integer calories;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**
* 
* @return
* The activity
*/
@JsonProperty("activity")
public String getActivity() {
return activity;
}

/**
* 
* @param activity
* The activity
*/
@JsonProperty("activity")
public void setActivity(String activity) {
this.activity = activity;
}

/**
* 
* @return
* The group
*/
@JsonProperty("group")
public String getGroup() {
return group;
}

/**
* 
* @param group
* The group
*/
@JsonProperty("group")
public void setGroup(String group) {
this.group = group;
}

/**
* 
* @return
* The duration
*/
@JsonProperty("duration")
public Integer getDuration() {
return duration;
}

/**
* 
* @param duration
* The duration
*/
@JsonProperty("duration")
public void setDuration(Integer duration) {
this.duration = duration;
}

/**
* 
* @return
* The distance
*/
@JsonProperty("distance")
public Integer getDistance() {
return distance;
}

/**
* 
* @param distance
* The distance
*/
@JsonProperty("distance")
public void setDistance(Integer distance) {
this.distance = distance;
}

/**
* 
* @return
* The steps
*/
@JsonProperty("steps")
public Integer getSteps() {
return steps;
}

/**
* 
* @param steps
* The steps
*/
@JsonProperty("steps")
public void setSteps(Integer steps) {
this.steps = steps;
}

/**
* 
* @return
* The calories
*/
@JsonProperty("calories")
public Integer getCalories() {
return calories;
}

/**
* 
* @param calories
* The calories
*/
@JsonProperty("calories")
public void setCalories(Integer calories) {
this.calories = calories;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}