generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from CDCgov/serde
better serde handling - v 1.3.10
- Loading branch information
Showing
8 changed files
with
149 additions
and
35 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T> : JsonSerializer<T>, JsonDeserializer<T> { | ||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |