From a32a60e735695e81bced1b7adf7ee6893a71642a Mon Sep 17 00:00:00 2001 From: Elizabeth Healy Date: Wed, 20 Nov 2024 11:32:10 -0500 Subject: [PATCH] dont use jsonadapter annotation, call deserializer manually --- .../main/java/io/opentdf/platform/sdk/Manifest.java | 5 +++-- sdk/src/main/java/io/opentdf/platform/sdk/TDF.java | 6 +++++- .../java/io/opentdf/platform/sdk/ZipReaderTest.java | 10 +++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/sdk/src/main/java/io/opentdf/platform/sdk/Manifest.java b/sdk/src/main/java/io/opentdf/platform/sdk/Manifest.java index b42fafc2..5ad91293 100644 --- a/sdk/src/main/java/io/opentdf/platform/sdk/Manifest.java +++ b/sdk/src/main/java/io/opentdf/platform/sdk/Manifest.java @@ -42,13 +42,14 @@ * of data integrity, encryption, payload, and assertions within a certain * context. */ -@JsonAdapter(Manifest.ManifestDeserializer.class) // Custom deserializer public class Manifest { private static final String kAssertionHash = "assertionHash"; private static final String kAssertionSignature = "assertionSig"; - private static final Gson gson = new Gson(); + private static final Gson gson = new GsonBuilder() + .registerTypeAdapter(Manifest.class, new ManifestDeserializer()) + .create(); @Override public boolean equals(Object o) { diff --git a/sdk/src/main/java/io/opentdf/platform/sdk/TDF.java b/sdk/src/main/java/io/opentdf/platform/sdk/TDF.java index f5ea5cfc..92a7be8f 100644 --- a/sdk/src/main/java/io/opentdf/platform/sdk/TDF.java +++ b/sdk/src/main/java/io/opentdf/platform/sdk/TDF.java @@ -1,11 +1,13 @@ package io.opentdf.platform.sdk; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.nimbusds.jose.*; import io.opentdf.platform.policy.Value; import io.opentdf.platform.policy.attributes.AttributesServiceGrpc.AttributesServiceFutureStub; import io.opentdf.platform.sdk.Config.TDFConfig; +import io.opentdf.platform.sdk.Manifest.ManifestDeserializer; import io.opentdf.platform.sdk.Autoconfigure.AttributeValueFQN; import io.opentdf.platform.sdk.Config.KASInfo; @@ -75,7 +77,9 @@ public TDF() { private static final SecureRandom sRandom = new SecureRandom(); - private static final Gson gson = new Gson(); + private static final Gson gson = new GsonBuilder() + .registerTypeAdapter(Manifest.class, new ManifestDeserializer()) + .create(); public class SplitKeyException extends IOException { public SplitKeyException(String errorMessage) { diff --git a/sdk/src/test/java/io/opentdf/platform/sdk/ZipReaderTest.java b/sdk/src/test/java/io/opentdf/platform/sdk/ZipReaderTest.java index 1eb55307..5c47710c 100644 --- a/sdk/src/test/java/io/opentdf/platform/sdk/ZipReaderTest.java +++ b/sdk/src/test/java/io/opentdf/platform/sdk/ZipReaderTest.java @@ -1,5 +1,9 @@ package io.opentdf.platform.sdk; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import io.opentdf.platform.sdk.Manifest.ManifestDeserializer; + import org.apache.commons.compress.archivers.zip.Zip64Mode; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; @@ -36,7 +40,11 @@ public void testReadingExistingZip() throws Exception { if (entry.getName().endsWith(".json")) { entry.getData().transferTo(stream); var data = stream.toString(StandardCharsets.UTF_8); - var map = new Gson().fromJson(data, Map.class); + var gson = new GsonBuilder() + .registerTypeAdapter(Manifest.class, new ManifestDeserializer()) + .create(); + var map = gson.fromJson(data, Map.class); + assertThat(map.get("encryptionInformation")).isNotNull(); } }