Skip to content

Commit 125d6c6

Browse files
author
Grace Calianese
committed
return empty string if UnknownField's data is null
1 parent 864f8e9 commit 125d6c6

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

  • model/src/main/java/com/basistech/rosette/apimodel/recordsimilarity/records

model/src/main/java/com/basistech/rosette/apimodel/recordsimilarity/records/UnknownField.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,26 @@ public UnknownField(JsonNode data) {
3939
//There's probably a better way to do this
4040
@JsonValue
4141
public Object getData() {
42-
if (data != null && data.isObject()) {
43-
Iterator<Map.Entry<String, JsonNode>> fields = data.fields();
44-
Map<String, JsonNode> map = new LinkedHashMap<>();
45-
while (fields.hasNext()) {
46-
Map.Entry<String, JsonNode> fieldEntry = fields.next();
47-
map.put(fieldEntry.getKey(), fieldEntry.getValue());
48-
}
49-
try {
50-
ObjectMapper mapper = new ObjectMapper();
51-
String jsonString = mapper.writeValueAsString(map);
52-
return mapper.readTree(jsonString);
53-
} catch (JsonProcessingException e) {
54-
return this.data;
42+
if (data == null) {
43+
return "";
44+
} else {
45+
if (data.isObject()) {
46+
Iterator<Map.Entry<String, JsonNode>> fields = data.fields();
47+
Map<String, JsonNode> map = new LinkedHashMap<>();
48+
while (fields.hasNext()) {
49+
Map.Entry<String, JsonNode> fieldEntry = fields.next();
50+
map.put(fieldEntry.getKey(), fieldEntry.getValue());
51+
}
52+
try {
53+
ObjectMapper mapper = new ObjectMapper();
54+
String jsonString = mapper.writeValueAsString(map);
55+
return mapper.readTree(jsonString);
56+
} catch (JsonProcessingException e) {
57+
return this.data;
58+
}
5559
}
60+
// if given input is not an Object node, it's a String so return it
61+
return this.data;
5662
}
57-
// if given input is not an Object node, it's a String so return it
58-
return this.data;
5963
}
6064
}

0 commit comments

Comments
 (0)