PageRenderTime 102ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/tmm/nosql/mongodb/helper/JsonHelper.java

https://github.com/robhinds/SpringMongoIntegrationExample
Java | 34 lines | 29 code | 5 blank | 0 comment | 2 complexity | ffaf5be77fa857550275591eba3de4c9 MD5 | raw file
  1. package com.tmm.nosql.mongodb.helper;
  2. import org.apache.commons.lang.WordUtils;
  3. import com.google.gson.JsonArray;
  4. import com.google.gson.JsonObject;
  5. import com.tmm.nosql.mongodb.domain.Resume;
  6. import com.tmm.nosql.mongodb.domain.ResumePage;
  7. import com.tmm.nosql.mongodb.domain.Section;
  8. public class JsonHelper {
  9. public static JsonObject buildJson(Resume r){
  10. JsonObject j = new JsonObject();
  11. j.addProperty("userName", WordUtils.capitalize(r.getId()));
  12. JsonArray pageArray = new JsonArray();
  13. for (ResumePage rp : r.getPages()){
  14. JsonObject page = new JsonObject();
  15. page.addProperty("pageName", WordUtils.capitalize(rp.getTitle()));
  16. JsonArray secArray = new JsonArray();
  17. for (Section s : rp.getSections()){
  18. JsonObject sec = new JsonObject();
  19. sec.addProperty("sectionTitle", WordUtils.capitalize(s.getSectionTitle()));
  20. sec.addProperty("sectionContent", s.getSectionContent());
  21. secArray.add(sec);
  22. }
  23. page.add("sections", secArray);
  24. pageArray.add(page);
  25. }
  26. j.add("pages", pageArray);
  27. return j;
  28. }
  29. }