allow missing indicators when writing JSON

This commit is contained in:
Jörg Prante 2016-09-16 23:26:53 +02:00
parent 76247bf40c
commit e4623a9e5c

View file

@ -44,6 +44,8 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo
public static final String TYPE_TAG = "_TYPE"; public static final String TYPE_TAG = "_TYPE";
private static final String EMPTY_STRING = "";
private static final String JSON_1 = "\":\""; private static final String JSON_1 = "\":\"";
private final Lock lock = new ReentrantLock(); private final Lock lock = new ReentrantLock();
@ -262,8 +264,13 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo
if (count > 0) { if (count > 0) {
sb.append(","); sb.append(",");
} }
sb.append("\"").append(marcField.getTag()).append("\":{\"") String tag = marcField.getTag();
.append(marcField.getIndicator().replace(' ', '_')).append("\":"); String indicator = marcField.getIndicator();
if (indicator == null) {
indicator = EMPTY_STRING;
}
sb.append("\"").append(tag).append("\":{\"")
.append(indicator.replace(' ', '_')).append("\":");
if (marcField.getSubfields().size() == 1) { if (marcField.getSubfields().size() == 1) {
MarcField.Subfield subfield = marcField.getSubfields().get(0); MarcField.Subfield subfield = marcField.getSubfields().get(0);
sb.append("{\"").append(subfield.getId()).append(JSON_1).append(escape(subfield.getValue())).append("\"}"); sb.append("{\"").append(subfield.getId()).append(JSON_1).append(escape(subfield.getValue())).append("\"}");