Fix issue saving array of data from dataset

This commit is contained in:
George Kalampokis 2021-07-20 11:37:28 +03:00
parent 6fd81a9809
commit 15af25e292
1 changed files with 7 additions and 9 deletions

View File

@ -17,6 +17,7 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -201,13 +202,10 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin
@Override @Override
public void fromJsonObject(Map<String, Object> properties) { public void fromJsonObject(Map<String, Object> properties) {
try { try {
JSONArray jsonArray = new JSONArray(properties.get(this.id).toString()); ObjectMapper mapper = new ObjectMapper();
List<String> stringList = new LinkedList<>(); List<String> stringList = mapper.readValue(properties.get(this.id).toString(), LinkedList.class);
for (int i = 0; i < jsonArray.length(); i++) {
stringList.add(jsonArray.getJSONObject(i).toString());
}
this.value = stringList; this.value = stringList;
} catch (JSONException | NullPointerException e) { } catch (JSONException | NullPointerException | IOException e) {
this.value = (String) properties.get(this.id); this.value = (String) properties.get(this.id);
} }
this.multiplicityItems = new LinkedList<>(); this.multiplicityItems = new LinkedList<>();
@ -231,7 +229,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin
@Override @Override
public void toMap(Map<String, Object> fieldValues) { public void toMap(Map<String, Object> fieldValues) {
if (this.value != null) { if (this.value != null) {
if (this.viewStyle != null && this.viewStyle.getRenderStyle().equals("datasetIdentifier")) { if ((this.viewStyle != null && this.viewStyle.getRenderStyle().equals("datasetIdentifier") || this.value instanceof Collection)) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
String valueString = null; String valueString = null;
try { try {
@ -240,7 +238,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
} else if (this.value instanceof Collection) { } /*else if (this.value instanceof Collection) {
Collection valueCollection = (Collection) this.value; Collection valueCollection = (Collection) this.value;
StringBuilder valueBuilder = new StringBuilder(); StringBuilder valueBuilder = new StringBuilder();
valueBuilder.append("["); valueBuilder.append("[");
@ -252,7 +250,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin
} }
valueBuilder.append("]"); valueBuilder.append("]");
fieldValues.put(this.id, valueBuilder.toString()); fieldValues.put(this.id, valueBuilder.toString());
} else { }*/ else {
fieldValues.put(this.id, this.value.toString()); fieldValues.put(this.id, this.value.toString());
} }
} else { } else {