Closed ydanneg closed 7 months ago
There is a problem: #137 (comment)
Indeed.
We need to be able to reproduce this. Took the unit-test that you provided in your gist. Can I ask you to include a similar unit-test to this PR?
Something like:
class SerializationTest {
@Test
fun `Can serialize and deserialize a PresentationDefinition`() {
val supportedClaimFormats =
listOf(SupportedClaimFormat.jwt(ClaimFormat.JwtType.SD_JWT, setOf(JwtAlgorithm.DigSig.ES256))!!)
val presentationDefinition = PresentationDefinition(
id = Id("pdId"),
inputDescriptors = emptyList(),
name = Name("name"),
purpose = Purpose("purpose"),
format = Format(supportedClaimFormats),
submissionRequirements = listOf(),
)
testSerialization(presentationDefinition)
}
@Test
fun `format test`() {
testSerialization("v2.0.0/presentation-definition/format_example.json")
}
@Test
fun `basic example`() {
testSerialization("v2.0.0/presentation-definition/basic_example.json")
}
@Test
fun `single group example`() {
testSerialization("v2.0.0/presentation-definition/single_group_example.json").also {
it.submissionRequirements?.forEach { x -> println(x) }
}
}
@Test
fun `multi group example`() {
testSerialization("v2.0.0/presentation-definition/multi_group_example.json").also {
it.submissionRequirements?.forEach { x -> println(x) }
}
}
@Test
fun `mDL example`() {
testSerialization("v2.0.0/presentation-definition/mDL-example.json").also {
it.submissionRequirements?.forEach { x -> println(x) }
}
}
private fun testSerialization(f: String): PresentationDefinition =
assertDoesNotThrow {
val pd = PresentationExchange.jsonParser.decodePresentationDefinition(load(f)!!).getOrThrow()
testSerialization(pd)
pd
}
private fun load(f: String): InputStream? =
PresentationDefinitionTest::class.java.classLoader.getResourceAsStream(f)
}
private inline fun <reified T> testSerialization(pd: T) {
val deserialized = deserialize<T>(serialize(pd))
assertEquals(pd, deserialized)
}
private fun serialize(obj: Any?): ByteArray =
ByteArrayOutputStream().use {
ObjectOutputStream(it).writeObject(obj)
it.toByteArray()
}
private inline fun <reified T> deserialize(bytes: ByteArray): T =
ObjectInputStream(ByteArrayInputStream(bytes)).use { out ->
out.readObject() as T
}
@ydanneg thanks.
Now it's reproducible. Need to sort out the Filter = JsonObject
problem, I guess :thinking:
@ydanneg
I think we have found an alternative solution on this. In a nutshell involves changing the Filter from being an alias of JsonObject
to be a value class which contains a json as string and a custom JsonSerializer.
I am not sure how we should proceed this PR. I see the following options:
Fitler
add the test and the java.io.Serializable
Filter
and then you can rebase your branch from main.What do you think?
I can rebase later, sure.
@ydanneg I see that I can write to your branch. Is it ok with you to apply the changes on your branch ?
(On Monday :smile: )
@ydanneg I see that I can write to your branch. Is it ok with you to apply the changes on your branch ?
(On Monday :smile: )
sure. go ahead! :)
@vafeini Can you please review this PR? If you agree we can proceed and perhaps release a fix version.
fixes https://github.com/eu-digital-identity-wallet/eudi-lib-jvm-presentation-exchange-kt/issues/137