From 9928094a9fa5c36ad0356b2bef941203b74877ef Mon Sep 17 00:00:00 2001 From: Julian Hochstetter <julian.hochstetter@mni.thm.de> Date: Wed, 17 Oct 2012 20:20:32 +0200 Subject: [PATCH] Task #4029: load answers from json and put the resulting list to the questions object --- src/main/java/de/thm/arsnova/dao/CouchDBDao.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java index e2fe3e7ea..f720cee38 100644 --- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java +++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -34,8 +35,10 @@ import net.sf.ezmorph.Morpher; import net.sf.ezmorph.MorpherRegistry; import net.sf.ezmorph.bean.BeanMorpher; import net.sf.ezmorph.bean.MorphDynaBean; +import net.sf.json.JSONArray; import net.sf.json.JSONException; import net.sf.json.JSONObject; +import net.sf.json.JsonConfig; import net.sf.json.util.JSONUtils; import org.apache.commons.beanutils.DynaBean; @@ -218,12 +221,8 @@ public class CouchDBDao implements IDatabaseDao { morpherRegistry.registerMorpher(dynaMorpher); for (Document d : questions.getResults()) { Question q = (Question) JSONObject.toBean(d.getJSONObject().getJSONObject("value"), Question.class); - List<PossibleAnswer> answers = new ArrayList<PossibleAnswer>(); - for(Object answer : q.getPossibleAnswers()) { - PossibleAnswer a = (PossibleAnswer) morpherRegistry.morph(PossibleAnswer.class, answer); - answers.add(a); - } - q.setPossibleAnswers(answers); + Collection<PossibleAnswer> answers = JSONArray.toCollection(d.getJSONObject().getJSONObject("value").getJSONArray("possibleAnswers"), PossibleAnswer.class); + q.setPossibleAnswers(new ArrayList<PossibleAnswer>(answers)); result.add(q); } -- GitLab