From e45038d31a5714161dcad4719f39b526f92bb4f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prante?= Date: Mon, 7 Nov 2022 18:40:46 +0100 Subject: [PATCH] fix handling of meta tags in JSON writer, clean style constructors, let the meta fields be appended at the end in JSON, not at the beginning, because it is the natural order --- gradle.properties | 2 +- src/main/java/org/xbib/marc/MarcRecord.java | 12 ++- .../org/xbib/marc/json/MarcJsonWriter.java | 66 +++++++------ .../java/org/xbib/marc/ConcurrencyTest.java | 3 +- .../java/org/xbib/marc/MarcRecordTest.java | 4 +- src/test/java/org/xbib/marc/ZDBTest.java | 5 +- .../xbib/marc/dialects/mab/MabXmlTest.java | 4 +- .../xbib/marc/json/MarcJsonWriterTest.java | 96 +++++++++++++++---- .../dialects/mab/mabxml-example.xml.jsonl | 6 +- .../org/xbib/marc/json/chabon-loc.mrc.json | 2 +- .../org/xbib/marc/json/chabon.mrc.json | 2 +- .../resources/org/xbib/marc/json/multi.json | 4 +- .../xbib/marc/json/rism_190101037.mrc.json | 2 +- .../org/xbib/marc/json/summerland.mrc.json | 2 +- .../org/xbib/marc/zdbtitutf8.mrc.json | 16 ++-- 15 files changed, 150 insertions(+), 76 deletions(-) diff --git a/gradle.properties b/gradle.properties index 78971fc..02abcbe 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group = org.xbib name = marc -version = 2.9.4 +version = 2.9.5 org.gradle.warning.mode = ALL diff --git a/src/main/java/org/xbib/marc/MarcRecord.java b/src/main/java/org/xbib/marc/MarcRecord.java index 4f4f930..a4873a1 100644 --- a/src/main/java/org/xbib/marc/MarcRecord.java +++ b/src/main/java/org/xbib/marc/MarcRecord.java @@ -447,9 +447,6 @@ public class MarcRecord implements Map { @SuppressWarnings("unchecked") private Map createMapFromMarcFields(boolean stable) { Map map = stable ? new TreeMap<>() : new LinkedHashMap<>(); - map.put(FORMAT_TAG, format); - map.put(TYPE_TAG, type); - map.put(LEADER_TAG, recordLabel.toString()); for (MarcField marcField : marcFields) { String tag = marcField.getTag(); int repeat; @@ -494,6 +491,15 @@ public class MarcRecord implements Map { repeatMap.put(Integer.toString(repeat), marcField.getValue()); } } + if (format != null) { + map.put(FORMAT_TAG, format); + } + if (type != null) { + map.put(TYPE_TAG, type); + } + if (recordLabel != null && !RecordLabel.EMPTY.equals(recordLabel)) { + map.put(LEADER_TAG, recordLabel.toString()); + } return map; } diff --git a/src/main/java/org/xbib/marc/json/MarcJsonWriter.java b/src/main/java/org/xbib/marc/json/MarcJsonWriter.java index 69850db..42b67ba 100644 --- a/src/main/java/org/xbib/marc/json/MarcJsonWriter.java +++ b/src/main/java/org/xbib/marc/json/MarcJsonWriter.java @@ -73,7 +73,7 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo private boolean fatalErrors; - private final EnumSet