avoid NPEs when MarkProperties have null as their tags collection

This commit is contained in:
Axel Uhl
2020-12-08 16:51:14 +01:00
parent 5321a56c89
commit 00c9019239
6 changed files with 15 additions and 10 deletions
@@ -48,7 +48,9 @@ public class CourseTemplateJsonSerializer implements JsonSerializer<CourseTempla
result.put(FIELD_OPTIONAL_IMAGE_URL, courseTemplate.getOptionalImageURL());
result.put(FIELD_DEFAULT_NUMBER_OF_LAPS, courseTemplate.getDefaultNumberOfLaps());
final JSONArray tags = new JSONArray();
courseTemplate.getTags().forEach(tags::add);
if (courseTemplate.getTags() != null) {
courseTemplate.getTags().forEach(tags::add);
}
result.put(FIELD_TAGS, tags);
final JSONArray allMarkRoles = new JSONArray();
courseTemplate.getMarkRoles().forEach(markRole -> {
@@ -20,8 +20,10 @@ public class FreestyleMarkPropertiesJsonSerializer implements JsonSerializer<Fre
public JSONObject serialize(FreestyleMarkProperties commonMarkProperties) {
JSONObject result = commonMarkPropertiesJsonSerializer.serialize(commonMarkProperties);
JSONArray jsonTags = new JSONArray();
for (String tag : commonMarkProperties.getTags()) {
jsonTags.add(tag);
if (commonMarkProperties.getTags() != null) {
for (String tag : commonMarkProperties.getTags()) {
jsonTags.add(tag);
}
}
result.put(FIELD_TAGS, jsonTags);
return result;
@@ -1,6 +1,5 @@
package com.sap.sailing.server.gateway.serialization.impl;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import com.sap.sailing.domain.coursetemplate.MarkProperties;
@@ -22,8 +21,6 @@ public class MarkPropertiesJsonSerializer implements JsonSerializer<MarkProperti
public JSONObject serialize(MarkProperties markProperties) {
JSONObject result = new JSONObject();
result.put(FIELD_ID, markProperties.getId().toString());
final JSONArray tags = new JSONArray();
markProperties.getTags().forEach(tags::add);
result.putAll(commonMarkPropertiesWithTagsJsonSerializer.serialize(markProperties));
result.put(FIELD_POSITIONING, markProperties.getPositioningInformation() == null ? null :
positioningJsonSerializer.serialize(markProperties.getPositioningInformation()));