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