如何解决我如何序列化 (NewtonSoft) 一个类,该类包含一个名为 Type 的属性的接口?
我需要序列化此类的结果(Assembly Adyen,Version=6.0.0.0):
<Runtime.Serialization.DataContractAttribute>
Public Class PaymentResponse
Implements IEquatable(Of PaymentResponse),IValidatableObject
Public Sub New(...)
...
<Runtime.Serialization.DataMemberAttribute(Name:="action",EmitDefaultValue:=False)>
Public Property Action As IPaymentResponseAction
...
End Class
查看结果,我按预期有 Action.PaymentData、Action.PaymentMethodType、Action.Token、Action.[Type] 和 Action.Url: Screenshot of Autos
但是当我序列化结果时,
Dim tmp As String = Newtonsoft.Json.JsonConvert.SerializeObject(ret,GetType(PaymentResponse),New
Newtonsoft.Json.JsonSerializerSettings() With {.[Error] = AddressOf jsonerror})
我只得到:
{
"resultCode": "IdentifyShopper","action": {
"paymentData": "XXX","paymentMethodType": "scheme","token": "YYY"
},"authentication": {
"threeds2.fingerprintToken": "ZZZ"
},"details": [
{
"key": "threeds2.fingerprint","type": "text"
}
],"paymentData": "QQQ"
}
我的 Json 字符串中没有 Action.[Type] 和“Action.Url”。
jsonerror()
永远不会被击中。
编辑:我添加了一个跟踪器:
Dim tracewriter As Newtonsoft.Json.Serialization.ITraceWriter = New
Newtonsoft.Json.Serialization.MemoryTraceWriter
Dim tmp As String = Newtonsoft.Json.JsonConvert.SerializeObject(ret,New
Newtonsoft.Json.JsonSerializerSettings() With
{.TraceWriter = tracewriter,.[Error] = AddressOf
jsonerror})
一切看起来都很好,只是我没有得到操作。[type] 序列化:
2021-01-19T14:25:11.852 信息开始序列化
Adyen.Model.Checkout.PaymentResponse。小路 ''。 2021-01-19T14:25:11.854
信息开始序列化
Adyen.Model.Checkout.PaymentResponse+ResultCodeEnum 带转换器
Newtonsoft.Json.Converters.StringEnumConverter。路径“结果代码”。
2021-01-19T14:25:11.854 信息已完成序列化
Adyen.Model.Checkout.PaymentResponse+ResultCodeEnum 带转换器
Newtonsoft.Json.Converters.StringEnumConverter。路径“结果代码”。
2021-01-19T14:25:11.856 信息开始序列化
Adyen.Model.Checkout.Action.CheckoutThreeDS2FingerPrintAction。小路
'行动'。 2021-01-19T14:25:11.857 信息已完成序列化
Adyen.Model.Checkout.Action.CheckoutThreeDS2FingerPrintAction。小路
'行动'。 2021-01-19T14:25:11.857 信息开始序列化
System.Collections.Generic.Dictionary2[System.String,System.String]. Path 'authentication'. 2021-01-19T14:25:11.857 Info Finished serializing System.Collections.Generic.Dictionary
2[System.String,System.String]。
路径“认证”。 2021-01-19T14:25:11.857 信息开始
连载
System.Collections.Generic.List1[Adyen.Model.Checkout.InputDetail]. Path 'details'. 2021-01-19T14:25:11.857 Info Started serializing Adyen.Model.Checkout.InputDetail. Path 'details'. 2021-01-19T14:25:11.857 Info Finished serializing Adyen.Model.Checkout.InputDetail. Path 'details[0]'. 2021-01-19T14:25:11.857 Info Finished serializing System.Collections.Generic.List
1[Adyen.Model.Checkout.InputDetail]。
路径“详细信息”。 2021-01-19T14:25:11.860 信息已完成序列化
Adyen.Model.Checkout.PaymentResponse。小路 ''。 2021-01-19T14:25:11.860
详细序列化 JSON: { "resultCode": "IdentifyShopper",
“行动”: {
"支付数据": "XXX","paymentMethodType": "方案",“令牌”:“YYY”},“身份验证”:{
“threeds2.fingerprintToken”:“ZZZ”},“详细信息”:[
{
"key": "threeds2.fingerprint",“类型”:“文本”
} ],"paymentData": "QQQ" }
解决方法
这是 Adyen .NET 库中的一个错误。 IPaymentResponseAction
的实现类缺少 DataMember
注释。有一个 fix 可以合并,很快就会在下一个补丁版本中提供。建议您在发布时更新到补丁版本。
对于 URL 字段,它仅可用于某些操作,例如重定向,例如理想的付款方式。对于方案,如您的情况,URL 不适用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。