-
Notifications
You must be signed in to change notification settings - Fork 0
#12 take care the ftPayItemId is null if empty to avoid issues with b… #13
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,14 @@ public ReceiptRequest(string cbReceiptReference, ReceiptCaseBuilder buildableRec | |||||||||||||||||
| { | ||||||||||||||||||
| this.cbReceiptReference = cbReceiptReference; | ||||||||||||||||||
| this.cbChargeItems = cbChargeItems; | ||||||||||||||||||
| // verify that empty ftPayItemIDs are null | ||||||||||||||||||
| foreach (var payItem in cbPayItems) | ||||||||||||||||||
| { | ||||||||||||||||||
| if (payItem.ftPayItemId == "") | ||||||||||||||||||
| { | ||||||||||||||||||
| payItem.ftPayItemId = null; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+27
to
+34
|
||||||||||||||||||
| // verify that empty ftPayItemIDs are null | |
| foreach (var payItem in cbPayItems) | |
| { | |
| if (payItem.ftPayItemId == "") | |
| { | |
| payItem.ftPayItemId = null; | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
ftPayItemIdproperty is now declared asstring?but the initializer is still= string.Empty. Since[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]only omits a property when its value equals the type's default (nullfor reference types), an instance ofPayItemwhereftPayItemIdis never set will still serialize the property as""— not omit it. This defeats the purpose of the change, because anyPayItemthat isn't processed through theReceiptRequestconstructor (e.g. deserialized from JSON and re-serialized, or directly constructed outside ofReceiptRequest) will still emit"ftPayItemId": ""in the JSON payload.The default initializer should be changed from
= string.Emptyto= null(or simply removed, sincenullis already the implicit default forstring?), so that the[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]attribute works correctly and the property is omitted from serialization when no ID is assigned.