-
Notifications
You must be signed in to change notification settings - Fork 18
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
Invoice JSON deserialization error #31
Comments
Serialization and deserialization works with the Newtonsoft JSON serializer/deserializer. I saw that it is the one used in the library.
|
Because there is some non primitive type in the object, you need the proper json converters exposed by var str = NBitcoin.JsonConverters.Serializer.ToString(invoice); You can probably make a PR so your original code work by adding |
As you said, this is an issue related to the way I was trying serialization and deserialization and not an issue of the repo. The missing feature in this repo is that System.Text.Json serialization and deserialization is not supported. Are you referring to a pull request that would support System.Text.Json serializer/deserializer for the Invoice, in addition to the Newtonsoft one? BTW, just for information that may be useful to other developers on top of BTCPay that want to cache the invoice in their applications, this is how I serialized/deserialized a BTCPay Invoice into/from a text field in a database with EF Core; I followed a suggestion from here: https://stackoverflow.com/questions/44829824/how-to-store-json-in-an-entity-field-with-ef-core In my MyCustomModel
In my ApplicationDbContext
Now there are only problems related to the fact that a lot of the Invoice fields (e.g. PaymentCodes) are not actually serialized on purpose. Maybe extending from the Invoice and overriding the relevant ShouldSerialize methods could solve this. |
@gradientskier did not noticed you were using System.Text.Json. Yes, we are using newtonsoft. To be honest, the type here is weird. (see the code, not all fields are serialized as you saw) |
Dear BTCPay team,
I am using NBitpayClient 1.0.0.39:
I am trying to serialize and deserialize in JSON the invoice structure using System.Text.Json, where MyBTCPay is an instance of NBitpayClient.Bitpay:
But when I try to deserialize the jsonString into invoice2, I get the following error:
Do you have any suggestion about how I can properly serialize/deserialize a NBitpayClinet Invoice in JSON?
Many thanks in advance!
The text was updated successfully, but these errors were encountered: