diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/ExportXmlBuilder.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/ExportXmlBuilder.java index 3e94c7f4d..5f5c96786 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/ExportXmlBuilder.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/ExportXmlBuilder.java @@ -1,5 +1,7 @@ package eu.eudat.logic.utilities.documents.xml; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.exc.MismatchedInputException; import eu.eudat.logic.services.forms.VisibilityRuleService; import eu.eudat.logic.utilities.builders.XmlBuilder; import eu.eudat.models.data.components.commons.datafield.ExternalDatasetsData; @@ -19,6 +21,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.List; +import java.util.Map; import java.util.UUID; public class ExportXmlBuilder { @@ -98,16 +101,33 @@ public class ExportXmlBuilder { } if (field.getValue() != null) { Element valueField = element.createElement("value"); + ObjectMapper mapper = new ObjectMapper(); try { - JSONArray jsonArray = new JSONArray(field.getValue().toString()); + + List> jsonArray = mapper.readValue(field.getValue().toString(), List.class); +// JSONArray jsonArray = new JSONArray(field.getValue().toString()); StringBuilder sb = new StringBuilder(); - for (int i = 0; i < jsonArray.length(); i++) { + boolean firstTime = true; + for (Map jsonElement: jsonArray) { + if (!firstTime) { + sb.append(", "); + } + sb.append(jsonElement.get("label") != null ? jsonElement.get("label") : jsonElement.get("name")); + firstTime = false; + + } + /*for (int i = 0; i < jsonArray.length(); i++) { sb.append(jsonArray.getJSONObject(i).get("label").toString()); if (i != jsonArray.length() - 1) sb.append(", "); - } + }*/ valueField.setTextContent(sb.toString()); - } catch (JSONException ex) { - valueField.setTextContent(field.getValue().toString()); + } catch (IOException ex) { + try { + Map jsonElement = mapper.readValue(field.getValue().toString(), Map.class); + valueField.setTextContent((jsonElement.get("label") != null ? jsonElement.get("label").toString() : jsonElement.get("name").toString())); + } catch (IOException e) { + valueField.setTextContent(field.getValue().toString()); + } } elementField.appendChild(valueField); }