diff --git a/.vscode/settings.json b/.vscode/settings.json
deleted file mode 100644
index 6b502cd..0000000
--- a/.vscode/settings.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "cSpell.words": [
- "ATSDR",
- "CFPB",
- "ISSO",
- "cybersecurity"
- ]
-}
\ No newline at end of file
diff --git a/change-log.md b/change-log.md
new file mode 100644
index 0000000..d9fbbff
--- /dev/null
+++ b/change-log.md
@@ -0,0 +1,10 @@
+# Change Log - lib-hl7v2-nist-validator
+
+## v 1.3.10 - 2024/10/31
+
+- Improving Json serialization and deserialization to circumvent issues with mixing scala and kotlin classes
+ - Created a Gson Entity Adapter for the scala Entry interface.
+ - Created a Gson Exclusion strategy class to remove stackTrace and metaData from serialization.
+ - Encapsulated a gson instance (nistGson) on NistReport with the appropriate initialization of the adapter above and other configs.
+ -
+
diff --git a/pom.xml b/pom.xml
index 5ebdd3a..5115eb5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
lib-hl7v2-nist-validator
lib-hl7v2-nist-validator
Library wrapper around NIST HL7v2 Validator for validation of HL7 v2.x messages.
- 1.3.9
+ 1.3.10
jar
https://github.com/CDCgov/lib-hl7v2-nist-validator
@@ -80,20 +80,20 @@
-
- org.apache.maven.plugins
- maven-gpg-plugin
- 3.2.5
-
-
- sign-artifacts
- verify
-
- sign
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
org.sonatype.central
central-publishing-maven-plugin
diff --git a/src/main/java/gov/cdc/EntryInterfaceAdapter.kt b/src/main/java/gov/cdc/EntryInterfaceAdapter.kt
new file mode 100644
index 0000000..02934bc
--- /dev/null
+++ b/src/main/java/gov/cdc/EntryInterfaceAdapter.kt
@@ -0,0 +1,16 @@
+package gov.cdc
+
+import com.google.gson.*
+import gov.nist.validation.report.impl.EntryImpl
+import java.lang.reflect.Type
+
+class EntryInterfaceAdapter : JsonSerializer, JsonDeserializer {
+ override fun deserialize(jsonElement: JsonElement, type: Type, context: JsonDeserializationContext): T {
+ val jsonObject = jsonElement.asJsonObject
+ return context.deserialize(jsonObject, EntryImpl::class.java)
+ }
+
+ override fun serialize(src: T, type: Type, context: JsonSerializationContext): JsonElement {
+ return context.serialize(src)
+ }
+}
diff --git a/src/main/java/gov/cdc/GsonExclusionStrategy.kt b/src/main/java/gov/cdc/GsonExclusionStrategy.kt
new file mode 100644
index 0000000..7b9b5c3
--- /dev/null
+++ b/src/main/java/gov/cdc/GsonExclusionStrategy.kt
@@ -0,0 +1,15 @@
+package gov.cdc
+
+import com.google.gson.ExclusionStrategy
+import com.google.gson.FieldAttributes
+import gov.nist.validation.report.impl.EntryImpl
+
+class GsonExclusionStrategy : ExclusionStrategy {
+ override fun shouldSkipClass(clazz: Class<*>?): Boolean {
+ return false
+ }
+ override fun shouldSkipField(f: FieldAttributes): Boolean {
+ return (f.declaringClass === EntryImpl::class.java && f.name.equals("stackTrace")) ||
+ (f.declaringClass === EntryImpl::class.java && f.name.equals("metaData"))
+ }
+}
diff --git a/src/main/java/gov/cdc/NistReport.kt b/src/main/java/gov/cdc/NistReport.kt
index fc05090..06b1d52 100644
--- a/src/main/java/gov/cdc/NistReport.kt
+++ b/src/main/java/gov/cdc/NistReport.kt
@@ -2,15 +2,22 @@ package gov.cdc
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
+import com.google.gson.GsonBuilder
import com.google.gson.annotations.SerializedName
import gov.nist.validation.report.Entry
-import java.util.*
import java.util.concurrent.atomic.AtomicInteger
//JsonProperty is used for jackson
//SerialiedName is used for Gson.
@JsonInclude(JsonInclude.Include.NON_NULL)
class NistReport {
+ companion object {
+ val nistGson = GsonBuilder().disableHtmlEscaping().serializeNulls().registerTypeAdapter(
+ gov.nist.validation.report.Entry::class.java,
+ EntryInterfaceAdapter()
+ ).setExclusionStrategies(GsonExclusionStrategy()
+ ).create()
+ }
val entries: Entries = Entries()
@JsonProperty("error-count")
@SerializedName("error-count")
@@ -39,10 +46,14 @@ class NistReport {
}
data class SummaryCount(
+ @JsonProperty("structure")
+ @SerializedName("structure")
val structure: Int ,
@JsonProperty ("value-set")
@SerializedName("value-set")
val valueset: Int,
+ @JsonProperty("content")
+ @SerializedName("content")
val content: Int
)
@@ -53,14 +64,6 @@ class Entries {
@SerializedName("value-set")
var valueset = ArrayList()
}
-//
-//@JsonIgnoreProperties(ignoreUnknown = true)
-//class Entry {
-// var line = 0
-// var column = 0
-// var path: String? = null
-// var description: String? = null
-// var category: String? = null
-// var classification: String? = null
-//
-//}
\ No newline at end of file
+
+
+
diff --git a/src/test/java/gov/cdc/NistReportTest.kt b/src/test/java/gov/cdc/NistReportTest.kt
new file mode 100644
index 0000000..b894737
--- /dev/null
+++ b/src/test/java/gov/cdc/NistReportTest.kt
@@ -0,0 +1,39 @@
+package gov.cdc
+
+import gov.nist.validation.report.impl.EntryImpl
+import org.junit.jupiter.api.Test
+
+class NistReportTest {
+
+ @Test
+ fun testEntryToText() {
+ val entry = EntryImpl(
+ 3,
+ 33,
+ "SFT[1]-4",
+ "Unit Test error",
+ "Cat-1",
+ "Error")
+ println("\n\n")
+ println(entry.toText())
+ }
+
+ @Test
+ fun testMinimalEntry() {
+ val entry = EntryImpl(3,33, null, null, null, null)
+ println("\n\n")
+ println(entry.toText())
+
+ }
+ @Test
+ fun fullReportJSON() {
+ val report = this::class.java.getResource("/reportExample.json")?.readText()
+ val nistReport = NistReport.nistGson.fromJson(report, NistReport::class.java)
+
+ println(nistReport)
+
+ val serializeIt = NistReport.nistGson.toJson(nistReport)
+ println(serializeIt)
+
+ }
+}
\ No newline at end of file
diff --git a/src/test/resources/reportExample.json b/src/test/resources/reportExample.json
new file mode 100644
index 0000000..c8e1cf1
--- /dev/null
+++ b/src/test/resources/reportExample.json
@@ -0,0 +1,39 @@
+{
+ "entries": {
+ "structure": [
+ {
+ "line": 1,
+ "column": 1,
+ "path": "PATIENT_RESULT[1]",
+ "description": "The required Group PATIENT_RESULT (PATIENT_RESULT) is missing",
+ "category": "Usage",
+ "classification": "Error",
+ "stackTrace": null,
+ "metaData": null
+ },
+ {
+ "line": 1,
+ "column": 1,
+ "path": "SFT[1]",
+ "description": "The required Segment SFT (Software Segment) is missing",
+ "category": "Usage",
+ "classification": "Error",
+ "stackTrace": null,
+ "metaData": null
+ }
+ ],
+ "content": [],
+ "value-set": []
+ },
+ "error-count": {
+ "structure": 2,
+ "value-set": 0,
+ "content": 0
+ },
+ "warning-count": {
+ "structure": 0,
+ "value-set": 0,
+ "content": 0
+ },
+ "status": "STRUCTURE_ERRORS"
+}
\ No newline at end of file