-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐞 Bug: JSON roundtrip property broken for TxMetadataWithSchema
.
#4647
Comments
TxMetadataWithSchema
.TxMetadataWithSchema
.
This appears to be specific to the Given the following import: > import Cardano.Api.TxMetadata And the following metadata: > m =
TxMetadata
{ unTxMetadata = fromList
[ ( 0
, TxMetaMap
[ ( TxMetaText "k", TxMetaText "v1" )
, ( TxMetaText "k", TxMetaText "v2" )
]
)
]
} It is possible to perform a JSON round trip with the > metadataFromJson TxMetadataJsonDetailedSchema
(metadataToJson TxMetadataJsonDetailedSchema m)
== Right m
True But not possible to perform a JSON round trip with the > metadataFromJson TxMetadataJsonNoSchema
(metadataToJson TxMetadataJsonNoSchema m)
== Right m
False This is because the > metadataToJson TxMetadataJsonNoSchema m
Object (fromList [("0",Object (fromList [("k",String "v2")]))]) Which when rendered as JSON produces the following string: > BL.putStrLn $ Aeson.encode $ metadataToJson TxMetadataJsonNoSchema m
{"0":{"k":"v2"}} The preservation of only the latest key-value mapping is consistent with the behaviour of Going back to > BL.putStrLn $ Aeson.encode $ metadataToJson TxMetadataJsonDetailedSchema m
{ "0":
{ "map":
[ { "k": {"string":"k"}
, "v": {"string":"v1"}
}
, { "k": {"string":"k"}
, "v": {"string":"v2"}
}
]
}
} Thus making it possible to satisfy the JSON round-trip property. |
From the perspective of the upstream Source code extract: -- This uses the \"no schema\" mapping. Note that with this mapping it is /not/
-- the case that any tx metadata can be converted to JSON and back to give the
-- original value. |
TxMetadataWithSchema
.TxMetadataWithSchema
.
Version
fae66a5
Description
The JSON encoding roundtrip property is not always satisfied for the
TxMetadataWithSchema
type.Here's a PR that demonstrates the failure:
TxMetadataWithSchema
. #4646Why is this a bug?
There is a long-standing convention that types used in the HTTP API should satisfy the following JSON round trip property:
decode . encode == id
The text was updated successfully, but these errors were encountered: