fix NPE in JSON writing

This commit is contained in:
Jörg Prante 2022-11-22 16:26:48 +01:00
parent 48098e22fd
commit 8192830b75
2 changed files with 23 additions and 10 deletions

View file

@ -1,5 +1,5 @@
group = org.xbib group = org.xbib
name = marc name = marc
version = 2.9.6 version = 2.9.7
org.gradle.warning.mode = ALL org.gradle.warning.mode = ALL

View file

@ -458,18 +458,31 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo
if (c5 > 0) { if (c5 > 0) {
sb.append(","); sb.append(",");
} }
sb.append("\"").append(escape(s)).append("\""); if (s != null) {
sb.append("\"").append(escape(s)).append("\"");
} else {
sb.append("null");
}
c5++; c5++;
} }
sb.append("]"); sb.append("]");
} else { } else {
sb.append("\"").append(escape(subfield.getValue().toString())).append("\""); Object object = subfield.getValue();
if (object != null) {
sb.append("\"").append(escape(object.toString())).append("\"");
} else {
sb.append("null");
}
} }
c4++; c4++;
sb.append("}"); sb.append("}");
} }
} else { } else {
sb.append("\"").append(escape(value2.toString())).append("\""); if (value2 != null) {
sb.append("\"").append(escape(value2.toString())).append("\"");
} else {
sb.append("null");
}
} }
c3++; c3++;
} }
@ -478,10 +491,10 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo
} }
sb.append("}"); sb.append("}");
} else { } else {
if (value == null) { if (value != null) {
sb.append("null");
} else {
sb.append("\"").append(escape(value.toString())).append("\""); sb.append("\"").append(escape(value.toString())).append("\"");
} else {
sb.append("null");
} }
} }
c1++; c1++;
@ -493,10 +506,10 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo
} }
sb.append("]"); sb.append("]");
} else { } else {
if (o == null) { if (o != null) {
sb.append("null");
} else {
sb.append("\"").append(escape(o.toString())).append("\""); sb.append("\"").append(escape(o.toString())).append("\"");
} else {
sb.append("null");
} }
} }
c0++; c0++;