【发布时间】:2021-04-23 17:55:12
【问题描述】:
我需要序列化这个类的结果(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,
GetType(PaymentResponse), 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.Dictionary
2[System.String,System.String]. Path 'authentication'. 2021-01-19T14:25:11.857 Info Finished serializing System.Collections.Generic.Dictionary2[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.List1[Adyen.Model.Checkout.InputDetail]。 路径“详细信息”。 2021-01-19T14:25:11.860 信息完成序列化 Adyen.Model.Checkout.PaymentResponse。小路 ''。 2021-01-19T14:25:11.860 详细序列化 JSON:{“resultCode”:“IdentifyShopper”,
“行动”: { "paymentData": "XXX", "paymentMethodType": "方案", “令牌”:“YYY”},“身份验证”:{ “threeds2.fingerprintToken”:“ZZZ”},“详细信息”:[ { "key": "threeds2.fingerprint", “类型”:“文本” } ], "paymentData": "QQQ" }
【问题讨论】:
标签: .net jsonconvert adyen