List of usage examples for org.json.simple JSONArray toJSONString
public String toJSONString()
From source file:org.aprilis.jrest.pull.Pull.java
/** * /*from ww w.j av a2 s .c o m*/ * @param sessionKey * @param jrestKey * @param jsonData * @return */ @SuppressWarnings("unchecked") @GET public Response executePull(@HeaderParam(Constants.SESSION_KEY) String sessionKey, @HeaderParam(Constants.JREST_KEY) String jrestKey, @DefaultValue(Constants.DEFAULT_JSON_DATA) @HeaderParam(Constants.JSON_DATA) String jsonData) { /* * */ if (moSessionStore.isSystemInReadyState() == false) { mLogger.fatal(Exceptions.gsSystemInHaltState); return Response.status(HttpCodes.SERVICE_UNAVAILABLE).entity(Exceptions.gsSystemInHaltState).build(); } // if (moSessionStore.isSystemInReadyState() == false) try { // 1. Check all the parameter except jsonData - Done // 2. Verify session - Done // 3. Verify jrest key permission by user - Done // 4. Build query - Done // 5. Acquire executor - Done // 6. Execute - Done // 7. Release executor - Done // 8. Form response base on execute state and return - Done // mLogger.debug(String.format(Exceptions.gsInfoSessionAndJrestKey, jrestKey, sessionKey)); if (sessionKey != null && jrestKey != null) { if (moSessionStore.isSessionValid(sessionKey)) { Definition jrestDefinition = moStore.getDefinition(jrestKey, true); if (jrestDefinition != null) { HashSet<String> hsetApiRoles = moStore.getDefinition(jrestKey, true).getRoles(); mLogger.debug(String.format(Exceptions.gsSessionIsValid, sessionKey)); moExecutor = null; msSqlQuery = null; moResultSet = null; moResultMetaData = null; if (moSessionStore.isRoleSetValid(sessionKey, hsetApiRoles)) { mLogger.debug( String.format(Exceptions.gsRolesVerificationPassed, sessionKey, jrestKey)); moReflect.setDefinition(jrestDefinition); moReflect.setRestJsonData(jsonData); if (jrestDefinition.getFqcnBefore() != null) { /* * Execute Before method if it has been configured. If the * before method is not successful, we expect it to throw an * exception which we catch and halt processing of the request. */ try { String sBeforeMethodResult = moReflect.executeBeforeMethod(); /* * If before method is configured and if its results is to be * consumed by JRest consume the result of beforeMethod and * pass it to the QueryBinder class. */ if (jrestDefinition.useResultFromBefore() == true) { if (sBeforeMethodResult != null) { msSqlQuery = moQueryBinder.buildQueryForKey(jrestKey, sBeforeMethodResult, Constants.gshDefTypeGet); } else { mLogger.error(Exceptions.gsBeforeMethodOutputIsNull); return Response.status(HttpCodes.PRECONDITION_FAILURE) .entity(Exceptions.gsBeforeMethodOutputIsNull).build(); } // if (sBeforeMethodResult != null) } else { // Do not consume output of Before method msSqlQuery = moQueryBinder.buildQueryForKey(jrestKey, jsonData, Constants.gshDefTypeGet); } // if (jrestDefinition.useResultFromBefore() == true) } catch (Exception e) { mLogger.error(Exceptions.gsBeforeMethodFailed); e.printStackTrace(moPrintWriter); mLogger.error(moStringWriter.toString()); return Response.status(HttpCodes.PRECONDITION_FAILURE) .entity(Exceptions.gsBeforeMethodFailed).build(); } // end of try .. catch block } else { /* * If before method was not configured, the original Json data * is passed to the QueryBinder. */ msSqlQuery = moQueryBinder.buildQueryForKey(jrestKey, jsonData, Constants.gshDefTypeGet); } // if (jrestDefinition.getFqcnBefore() != null) if (msSqlQuery == null) { mLogger.error(Exceptions.gsUnProcessableQuery); return Response.status(HttpCodes.UNPROCESSABLE_ENTITY) .entity(Exceptions.gsUnProcessableQuery).build(); } // if (msSqlQuery == null) mLogger.debug(msSqlQuery); // Acquire executor handle from the pool engine moExecutor = moExecutionEngine.acquireExecutorFromPool(); if (moExecutor != null) { // Trigger the query and check whether it was successful or // not mLogger.debug(String.format(Exceptions.gsFormedSqlQuery, msSqlQuery)); moResultSet = moExecutor.executeQuery(msSqlQuery); if (moResultSet != null && moResultSet.isBeforeFirst()) { JSONArray jsonResultSet = new JSONArray(); moResultMetaData = moResultSet.getMetaData(); mLogger.debug(String.format(Exceptions.gsResultColumnCount, moResultMetaData.getColumnCount())); while (moResultSet.next()) { JSONObject jsonRow = new JSONObject(); for (short columnIndex = Constants.gshColumnStartIndex; columnIndex <= moResultMetaData .getColumnCount(); columnIndex++) { /* * mLogger.trace( String.format( * Exceptions.gsResultSetRowInfo, * moResultMetaData.getColumnName( columnIndex ), * moResultSet.getString( columnIndex ) ) ); */ jsonRow.put(moResultMetaData.getColumnName(columnIndex), moResultSet.getString(columnIndex)); } // for (short columnIndex = ... ) jsonResultSet.add(jsonRow); } // while( moResultSet.next() ) moResultSet.close(); moExecutionEngine.releaseExecutorToPool(moExecutor); moResultMetaData = null; moResultSet = null; moExecutor = null; msSqlQuery = null; /* * Execute After method if it has been configured. If the * after method is not successful, we expect it to throw an * exception which we catch and return error. */ if (jrestDefinition.getFqcnAfter() != null) { try { String sAfterMethodResult = moReflect .executeAfterMethod(jsonResultSet.toJSONString()); return Response.status(HttpCodes.OK).entity(sAfterMethodResult).build(); } catch (Exception e) { mLogger.error(Exceptions.gsAfterMethodFailed); e.printStackTrace(moPrintWriter); mLogger.error(moStringWriter.toString()); return Response.status(HttpCodes.EXPECTATION_FAILED) .entity(Exceptions.gsAfterMethodFailed).build(); } // end of try .. catch block } // if (jrestDefinition.getFqcnAfter() != null) return Response.status(HttpCodes.OK).entity(jsonResultSet.toJSONString()) .build(); } else { mLogger.error(Exceptions.gsQueryResultedInNullSetMessage); return Response.status(HttpCodes.EXPECTATION_FAILED) .entity(Exceptions.gsQueryResultedInNullSet).build(); } // if (moResultSet != null) } else { return Response.status(HttpCodes.SERVICE_UNAVAILABLE) .entity(Exceptions.gsNoFreeExecutorsAvailable).build(); } // if (moExecutor != null) } // if (moSessionStore.isRoleSetValid(sessionKey, hsetApiRoles)) mLogger.error(String.format(Exceptions.gsRolesVerificationFailed, sessionKey, jrestKey)); return Response.status(HttpCodes.FORBIDDEN) .entity(String.format(Exceptions.gsRolesVerificationFailed, sessionKey, jrestKey)) .build(); } // if (jrestDefinition != null) mLogger.error(String.format(Exceptions.gsNoDefinitionFound, jrestKey)); return Response.status(HttpCodes.NOT_FOUND) .entity(String.format(Exceptions.gsNoDefinitionFound, jrestKey)).build(); } // if (moSessionStore.isSessionValid(sessionKey)) mLogger.error(String.format(Exceptions.gsSessionIsInValid, sessionKey)); return Response.status(HttpCodes.FORBIDDEN) .entity(String.format(Exceptions.gsSessionIsInValidMessage, sessionKey).toString()).build(); } // if (sessionKey != null && jrestKey != null) } catch (Exception e) { e.printStackTrace(moPrintWriter); mLogger.error(moStringWriter.toString()); } finally { if (moExecutor != null) { moExecutionEngine.releaseExecutorToPool(moExecutor); } if (moResultSet != null) { try { moResultSet.close(); } catch (SQLException e) { e.printStackTrace(moPrintWriter); mLogger.error(moStringWriter.toString()); } } msSqlQuery = null; moExecutor = null; moResultSet = null; moResultMetaData = null; } // end of try .. catch .. finally section return Response.status(HttpCodes.FORBIDDEN).build(); }
From source file:org.arkanos.pivotal_analytics.pivotal.PivotalAPI.java
/** * Downloads the stories for a given project. * // w ww . ja va 2s . co m * @param projectID specifies Pivotal ID reference to the Project. * @return a vector with a JSON String in an array per iteration. */ public Vector<String> downloadProjectContent(int projectID) { Vector<String> pages_iterations = new Vector<String>(); Vector<String> pages_icebox = new Vector<String>(); int max = 1; int current = 0; int page = 100000; CloseableHttpClient httpclient = HttpClientBuilder.create().build(); System.out.println("----------------------------------------"); try { /** Downloading Scheduled via Iterations for data transfer optimization **/ System.out.println("-- Downloading iterations --"); HttpGet httpget = new HttpGet(API_LOCATION_URL + "/projects/" + projectID + "/iterations?limit=100000"); httpget.addHeader("X-TrackerToken", token); System.out.println("Executing request for Project Content:\n" + httpget.getRequestLine()); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); System.out.println(response.getStatusLine()); if (response.getFirstHeader("X-Tracker-Pagination-Total") != null) { max = Integer.parseInt(response.getFirstHeader("X-Tracker-Pagination-Total").getValue()); } if (response.getFirstHeader("X-Tracker-Pagination-Limit") != null) { page = Integer.parseInt(response.getFirstHeader("X-Tracker-Pagination-Limit").getValue()); } while (entity != null && current < max) { System.out.println("Response content length: " + entity.getContentLength()); String result = ""; int r = 0; byte[] b = new byte[10240]; do { r = entity.getContent().read(b); if (r > 0) { result += new String(b, 0, r); } } while (r > 0); pages_iterations.add(result); current += page; if (current < max) { httpclient.close(); httpclient = HttpClientBuilder.create().build(); httpget = new HttpGet(API_LOCATION_URL + "/projects/" + projectID + "/iterations?limit=" + page + "&offset=" + current); httpget.addHeader("X-TrackerToken", token); System.out.println("Executing request for Project Content:\n" + httpget.getRequestLine()); response = httpclient.execute(httpget); entity = response.getEntity(); System.out.println(response.getStatusLine()); } } httpclient.close(); /** Downloading the icebox (unscheduled) **/ max = 1; current = 0; page = 100000; httpclient = HttpClientBuilder.create().build(); System.out.println("-- Downloading icebox --"); httpget = new HttpGet( API_LOCATION_URL + "/projects/" + projectID + "/stories?limit=100000&with_state=unscheduled"); httpget.addHeader("X-TrackerToken", token); System.out.println("Executing request for Project Content:\n" + httpget.getRequestLine()); response = httpclient.execute(httpget); entity = response.getEntity(); System.out.println(response.getStatusLine()); if (response.getFirstHeader("X-Tracker-Pagination-Total") != null) { max = Integer.parseInt(response.getFirstHeader("X-Tracker-Pagination-Total").getValue()); } if (response.getFirstHeader("X-Tracker-Pagination-Limit") != null) { page = Integer.parseInt(response.getFirstHeader("X-Tracker-Pagination-Limit").getValue()); } while (entity != null && current < max) { System.out.println("Response content length: " + entity.getContentLength()); String result = ""; int r = 0; byte[] b = new byte[10240]; do { r = entity.getContent().read(b); if (r > 0) { result += new String(b, 0, r); } } while (r > 0); pages_icebox.add(result); current += page; if (current < max) { httpclient.close(); httpclient = HttpClientBuilder.create().build(); httpget = new HttpGet(API_LOCATION_URL + "/projects/" + projectID + "/iterations?limit=" + page + "&offset=" + current); httpget.addHeader("X-TrackerToken", token); System.out.println("Executing request for Project Content:\n" + httpget.getRequestLine()); response = httpclient.execute(httpget); entity = response.getEntity(); System.out.println(response.getStatusLine()); } } /**Releasing System and Connection resources**/ httpclient.close(); } catch (ClientProtocolException e) { System.out.println( "[ERROR:ClientProtocolException] Error while downloading file, see error logs for stack trace."); e.printStackTrace(); } catch (IOException e) { System.out.println( "[ERROR:IOException] Error while saving the downloaded file, see error logs for stack trace."); e.printStackTrace(); } System.out.println("----------------------------------------"); JSONParser jp = new JSONParser(); Vector<String> iterations = new Vector<String>(); try { if (pages_icebox.size() > 0) { String icebox = "["; for (String p : pages_icebox) { icebox += p.substring(1, p.length() - 1) + ","; } icebox = icebox.substring(0, icebox.length() - 1) + "]"; iterations.add(icebox); } else { iterations.add("[]"); } for (String p : pages_iterations) { JSONArray ja = (JSONArray) jp.parse(p); for (Object i : ja.toArray()) { JSONArray stories = (JSONArray) ((JSONObject) i).get("stories"); iterations.add(stories.toJSONString()); } } } catch (ParseException e) { System.out.println("[ERROR:ParseException] There was a problem parsing the iterations/icebox."); e.printStackTrace(); } return iterations; }
From source file:org.daxplore.presenter.server.servlets.AdminPrefixServlet.java
@SuppressWarnings("unchecked") private static String listToJson(List<String> texts) { JSONArray jsonArray = new JSONArray(); jsonArray.addAll(texts);/*from w w w . j a va2 s. com*/ jsonArray.toJSONString(); return jsonArray.toJSONString(); }
From source file:org.daxplore.presenter.server.storage.StorageTools.java
/** * Get some questions from the questions metadata file. * //from w w w . j a v a2 s .c o m * <p>This is useful when answering an embed request, as the embed mode only * uses two of the defined questions: one for the question and one for * the perspective.</p> */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static String getQuestionDefinitions(PersistenceManager pm, String prefix, List<String> questionIDs, Locale locale) throws BadRequestException { try { JSONArray definitions = new JSONArray(); ContainerFactory containerFactory = new ContainerFactory() { @Override public Map createObjectContainer() { return new LinkedHashMap(); } @Override public List creatArrayContainer() { return new LinkedList(); } }; Reader reader = new StringReader(TextFileStore.getFile(pm, prefix, "meta/questions", locale, ".json")); JSONParser parser = new JSONParser(); List<Map> questionList = (List<Map>) parser.parse(reader, containerFactory); for (Map map : questionList) { Object o = map.get("column"); String column = (String) o; if (questionIDs.contains(column)) { definitions.add(map); } } return definitions.toJSONString(); } catch (IOException | ParseException e) { throw new BadRequestException("Failed to read question definitions", e); } }
From source file:org.dia.kafka.isatools.producer.ISAToolsKafkaProducer.java
private static JSONObject adjustUnifiedSchema(JSONObject parse) { JSONObject jsonObject = new JSONObject(); List invNames = new ArrayList<String>(); List invMid = new ArrayList<String>(); List invLastNames = new ArrayList<String>(); Set<Map.Entry> set = parse.entrySet(); for (Map.Entry entry : set) { String jsonKey = SolrKafkaConsumer.updateCommentPreffix(entry.getKey().toString()); String solrKey = ISA_SOLR.get(jsonKey); // System.out.println("solrKey " + solrKey); if (solrKey != null) { // System.out.println("jsonKey: " + jsonKey + " -> solrKey: " + solrKey); if (jsonKey.equals("Study_Person_First_Name")) { invNames.addAll(((JSONArray) JSONValue.parse(entry.getValue().toString()))); } else if (jsonKey.equals("Study_Person_Mid_Initials")) { invMid.addAll(((JSONArray) JSONValue.parse(entry.getValue().toString()))); } else if (jsonKey.equals("Study_Person_Last_Name")) { invLastNames.addAll(((JSONArray) JSONValue.parse(entry.getValue().toString()))); }/*from ww w .ja va 2s .c om*/ jsonKey = solrKey; } else { jsonKey = jsonKey.replace(" ", "_"); } jsonObject.put(jsonKey, entry.getValue()); } JSONArray jsonArray = new JSONArray(); for (int cnt = 0; cnt < invLastNames.size(); cnt++) { StringBuilder sb = new StringBuilder(); if (!StringUtils.isEmpty(invNames.get(cnt).toString())) sb.append(invNames.get(cnt)).append(" "); if (!StringUtils.isEmpty(invMid.get(cnt).toString())) sb.append(invMid.get(cnt)).append(" "); if (!StringUtils.isEmpty(invLastNames.get(cnt).toString())) sb.append(invLastNames.get(cnt)); jsonArray.add(sb.toString()); } if (!jsonArray.isEmpty()) { jsonObject.put("Investigator", jsonArray.toJSONString()); } return jsonObject; }
From source file:org.dia.kafka.solr.consumer.SolrKafkaConsumer.java
/** * Converts ISATools messages into Solr documents * * @param jsonObject/* w w w . j av a 2 s . co m*/ * @return */ private SolrInputDocument convertIsaMsgSolr(JSONObject jsonObject) { System.out.format("[%s] Processing msg from %s\n", this.getClass().getSimpleName(), DataSource.ISATOOLS); final SolrInputDocument inputDoc = new SolrInputDocument(); jsonObject.remove(SOURCE_TAG); Iterator<?> keys = jsonObject.keySet().iterator(); List<String> invNames = new ArrayList<String>(); List<String> invMid = new ArrayList<String>(); List<String> invLastNames = new ArrayList<String>(); while (keys.hasNext()) { String key = (String) keys.next(); String cleanKey = updateCommentPreffix(key); if (!ISA_IGNORED_SET.contains(cleanKey)) { if (cleanKey.equals("DA_Number")) { inputDoc.addField("id", jsonObject.get(key)); } else if (cleanKey.equals("Study_Person_First_Name")) { // dealing with investigators' names invNames.add(jsonObject.get(key).toString()); } else if (cleanKey.equals("Study_Person_Mid_Initials")) { invMid.add(jsonObject.get(key).toString()); } else if (cleanKey.equals("Description")) { invLastNames.add(jsonObject.get(key).toString()); } else if (cleanKey.equals("Tags")) { inputDoc.addField("Study_Tags", jsonObject.get(key)); } else if (cleanKey.equals("Created_with_configuration")) { inputDoc.addField("Created_With_Configuration", jsonObject.get(key)); } else {//if (!key.startsWith("_")){ inputDoc.addField(cleanKey, jsonObject.get(key)); } } } JSONArray jsonArray = new JSONArray(); for (int cnt = 0; cnt < invLastNames.size(); cnt++) { StringBuilder sb = new StringBuilder(); sb.append(invNames.get(cnt) != null ? invNames.get(cnt) : "").append(" "); sb.append(invMid.get(cnt) != null ? invMid.get(cnt) : "").append(" "); sb.append(invLastNames.get(cnt) != null ? invLastNames.get(cnt) : ""); jsonArray.add(sb.toString()); } if (!jsonArray.isEmpty()) inputDoc.addField("Investigator", jsonArray.toJSONString()); return inputDoc; }
From source file:org.eclipse.californium.proxy.HttpTranslator.java
public static void getHttpOptions(HttpRequest httpRequest, Response coapResponse, HttpResponse httpResponse) { // TODO Auto-generated method stub String response = coapResponse.getPayloadString(); JSONParser parser = new JSONParser(); try {/*from w w w .ja v a 2 s . c o m*/ JSONObject obj = (JSONObject) parser.parse(response); JSONArray allow = (JSONArray) obj.get("Allow"); JSONArray accept_post = (JSONArray) obj.get("Accept-Post"); JSONArray accept_patch = (JSONArray) obj.get("Accept-Patch"); if (allow != null) { String allow_string = allow.toJSONString(); allow_string = allow_string.replace("\"", ""); allow_string = allow_string.replace("[", ""); allow_string = allow_string.replace("]", ""); Header allow_header = new BasicHeader("Allow", allow_string); httpResponse.addHeader(allow_header); } if (accept_post != null) { String accept_post_string = accept_post.toJSONString(); accept_post_string = accept_post_string.replace("\"", ""); accept_post_string = accept_post_string.replace("\\", ""); accept_post_string = accept_post_string.replace("[", ""); accept_post_string = accept_post_string.replace("]", ""); Header accept_post_header = new BasicHeader("Accept-Post", accept_post_string); httpResponse.addHeader(accept_post_header); } if (accept_patch != null) { String accept_patch_string = accept_patch.toJSONString(); accept_patch_string = accept_patch_string.replace("\"", ""); accept_patch_string = accept_patch_string.replace("\\", ""); accept_patch_string = accept_patch_string.replace("[", ""); accept_patch_string = accept_patch_string.replace("]", ""); Header accept_patch_header = new BasicHeader("Accept-Patch", accept_patch_string); httpResponse.addHeader(accept_patch_header); } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.entermedia.websocket.annotation.AnnotationServer.java
protected void saveAnnotationData(String inCatalogid, String inCollectionId, String inAssetId, JSONObject inAnnotation) {//from w w w . ja va 2 s . co m String annotationid = (String) inAnnotation.get("id"); Searcher searcher = getSearcherManager().getSearcher(inCatalogid, "annotation"); Data data = (Data) searcher.searchById(annotationid); if (data == null) { data = searcher.createNewData(); } data.setProperty("id", annotationid); data.setProperty("collectionid", inCollectionId); data.setProperty("assetid", inAssetId); data.setProperty("date", (String) inAnnotation.get("date")); data.setProperty("user", (String) inAnnotation.get("user")); data.setProperty("comment", (String) inAnnotation.get("comment")); data.setProperty("color", (String) inAnnotation.get("color")); JSONArray array = (JSONArray) inAnnotation.get("fabricObjects"); if (array != null) { data.setProperty("fabricObjects", array.toJSONString()); } //user: null, // comment: "", // date : [], // fabricObjects: [], // assetid: null searcher.saveData(data, null); }
From source file:org.exoplatform.social.client.core.model.ActivityImplTest.java
@Test public void shouldJsonActivityParser() throws Exception { String jsonActivity1 = "{\"id\": \"1a2b3c4d5e6f7g8h9j\"," + "\"title\": \"Hello World!!!\"," + "\"appId\": \"\"," + "\"type\": \"DEFAULT_ACTIVITY\"," + "\"postedTime\": 123456789," //timestamp + "\"createdAt\": \"Fri Jun 17 06:42:26 +0000 2011\"," //The Date follows ISO 8601 + "\"priority\": 0.5, "//between 0.0 and 1.0, higher value => higher priority. + "\"templateParams\": {}," + "\"titleId\": \"\"," + "\"identityId\": \"123456789abcdefghi\"," //the identity id of the user who created this activity + "\"liked\": true," //is liked (favorites) by this authenticated identity + "\"likedByIdentities\": [{\"id\":1234567, \"providerId\":\"organization\", \"remoteId\":\"demo\", \"profile\":{\"fullName\":\"Demo GTN\", \"avatarUrl\":\"http://localhost:8080/profile/u/demo/avatar.jpg?u=12345\"}}]," + "\"totalNumberOfLikes\": 20" + "\"posterIdentity\": {\"id\":1234567, \"providerId\":\"organization\", \"remoteId\":\"demo\", \"profile\":{\"fullName\":\"Demo GTN\", \"avatarUrl\":\"http://localhost:8080/profile/u/demo/avatar.jpg?u=12345\"}}," //optional + "\"comments\": [{}]," //optional + "\"totalNumberOfComments\": 1234," + "\"activityStream\": {" + "\"type\": \"user\"," // or "space" + "\"fullName\": \"Root Root\"," + "\"prettyId\": \"root\"," // or space_abcde + "\"faviconUrl\": \"http://demo3.exoplatform.org/favicons/exo-default.jpg\"," + "\"title\": \"Activity Stream of Root Root\"," + "\"permaLink\": \"http://localhost:8080/profile/root\"" + "}" //optional + "}\""; RestActivity model3 = SocialJSONDecodingSupport.parser(RestActivity.class, jsonActivity1); assertEquals(model3.getIdentityId(), "123456789abcdefghi"); ///*from www . ja va 2 s . c om*/ JSONObject jsonObject = (JSONObject) JSONValue.parse(jsonActivity1); JSONArray jsonArray = (JSONArray) jsonObject.get("likedByIdentities"); // String actual = model3.getFieldAsString("likedByIdentities"); assertEquals(actual, jsonArray.toJSONString()); List<RestIdentity> identities = SocialJSONDecodingSupport.JSONArrayObjectParser(RestIdentity.class, actual); assertEquals(identities.size(), 1); }
From source file:org.exoplatform.social.client.core.model.ActivityImplTest.java
@Test public void shouldJsonActivityStreamArrayParser() throws Exception { String jsonActivity1 = "{\"activities\":[" + "{" + "\"appId\":null,\"identityId\":\"f845f6ed7f000101003ed4d98a09beb3\"," + "\"totalNumberOfComments\":0,\"liked\":false,\"templateParams\":{}," + "\"postedTime\":1309839511830,\"type\":\"DEFAULT_ACTIVITY\"," + "\"posterIdentity\":{},\"activityStream\":{}," + "\"id\":\"f884d11a7f000101000230e5c0e8a602\"," + "\"title\":\"hello\",\"priority\":null," + "\"createdAt\":\"Tue Jul 5 11:18:31 +0700 2011\"," + "\"likedByIdentities\":null,\"titleId\":null,\"comments\":null}" + "]}"; JSONObject jsonObject = (JSONObject) JSONValue.parse(jsonActivity1); JSONArray jsonArray = (JSONArray) jsonObject.get("activities"); RestActivity model3 = SocialJSONDecodingSupport .JSONArrayObjectParser(RestActivity.class, jsonArray.toJSONString()).get(0); assertEquals(model3.getIdentityId(), "f845f6ed7f000101003ed4d98a09beb3"); }