Source:
<code>public String addAssessment(PortletRequest request, PortletResponse response) throws Exception { initialize(request); initializeJSONData(request.getParameterMap()); Session session = HibernateUtil.getCurrentSession(); Assessment assessment = dbAssessmentsMap.entrySet().iterator().next().getValue(); List<AssessmentCriteria> sortedAssessmentCriteria = assessment.getSortedAssessmentCriteria(); List<CriterionArea> criterionAreas = new ArrayList<CriterionArea>(); for (AssessmentCriteria assessmentCriteria : sortedAssessmentCriteria) { criterionAreas.add(assessmentCriteria.getCriteriaArea()); } GoalVersion reactivatedGoalVersion = appraisal.getReactivatedGoalVersion(); if (reactivatedGoalVersion == null) { reactivatedGoalVersion = (GoalVersion) appraisal.getGoalVersions().toArray()[0]; } Integer nextSequence = calculateAssessmentSequence(dbAssessmentsMap); assessment = AppraisalMgr.createNewAssessment(reactivatedGoalVersion, nextSequence, criterionAreas); session.save(assessment); <START> String returnJSON = ""; <END> returnJSON += "{id:" + assessment.getId(); returnJSON += ", assessmentCriteria:{"; ArrayList<String> assessmentCriteriaJSON = new ArrayList<String>(); for(AssessmentCriteria criterion : assessment.getAssessmentCriteria()) { assessmentCriteriaJSON.add("\"" + criterion.getCriteriaArea().getName() + "\":" + criterion.getId()); } returnJSON += StringUtils.join(assessmentCriteriaJSON, ','); returnJSON += "}, status:\"success\"}"; System.out.println(returnJSON); return returnJSON; }</code><technical_language>building a more complicated json string here, do hand. Instead create a HashMap Gson library conver json. For example: <pre> HashMap fooMap = new HashMap(); HashMap criteriaMap = new HashMap(); criteriaMap.put("communication", 5); criteriaMap.put("teamwork", 7); fooMap.put("id", 12345); fooMap.put("assessmentCriteria", criteriaMap); Gson gson = new Gson(); System.out.println(gson.toJson(fooMap)); </pre></technical_language>

Target:
public String addAssessment(PortletRequest request, PortletResponse response) throws Exception { initialize(request); initializeJSONData(request.getParameterMap()); Session session = HibernateUtil.getCurrentSession(); Assessment assessment = dbAssessmentsMap.entrySet().iterator().next().getValue(); List<AssessmentCriteria> sortedAssessmentCriteria = assessment.getSortedAssessmentCriteria(); List<CriterionArea> criterionAreas = new ArrayList<CriterionArea>(); for (AssessmentCriteria assessmentCriteria : sortedAssessmentCriteria) { criterionAreas.add(assessmentCriteria.getCriteriaArea()); } GoalVersion reactivatedGoalVersion = appraisal.getReactivatedGoalVersion(); if (reactivatedGoalVersion == null) { reactivatedGoalVersion = (GoalVersion) appraisal.getGoalVersions().toArray()[0]; } Integer nextSequence = calculateAssessmentSequence(dbAssessmentsMap); assessment = AppraisalMgr.createNewAssessment(reactivatedGoalVersion, nextSequence, criterionAreas); session.save(assessment); HashMap jsonMap = new HashMap(); HashMap criteriaMap = new HashMap(); jsonMap.put("id", assessment.getId()); for(AssessmentCriteria criterion : assessment.getAssessmentCriteria()) { criteriaMap.put(criterion.getCriteriaArea().getName(), criterion.getId()); } jsonMap.put("assessmentCriteria", criteriaMap); jsonMap.put("status", "success"); Gson gson = new Gson(); return gson.toJson(jsonMap); }