Skip to content
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

v13.0.2 not preserving trailing zeros when deserializing decimals with 0 #2786

Open
Alperen2558 opened this issue Jan 3, 2023 · 5 comments

Comments

@Alperen2558
Copy link

Source/destination types

public sealed class Invoice
    {
        public Guid Id { get; set; }
        
        public string? InvoiceNumber { get; set; }

        public List<InvoiceLine>? InvoiceLines { get; set; }
    }

public sealed class InvoiceLine
    {
        public Guid Id { get; set; }
        
        public decimal VatAmount { get; set; }
        
        public decimal NetAmount { get; set; }
        
        public decimal TotalAmount { get; set; }
    }

Source/destination JSON

{
  "id": "d28888e9-2ba9-473a-a40f-e38cb54f9c25",
  "invoiceLines": [
    {
      "id": "b1bc25c7-0a67-405e-b82a-b39f63d6c1ad",
      "vatAmount": 0.00,
      "netAmount": 90.00,
      "totalAmount": 100.00
    },
    {
      "d": "3cdce072-1824-4c9e-8bfd-c9fd4e739f5a",
      "vatAmount": 15.00,
      "netAmount": 85.00,
      "totalAmount": 100.00
    }
  ]
}

Expected behavior

line1-> "vatAmount": 0.00, should have been serialized as "0.00"

Actual behavior

line1-> "vatAmount": 0.00, have been serialized as "0"

Steps to reproduce

public class TrailingZerosTests
    {
        [Fact]
        public void DeserializeObject_WhenSomeZerosOnADecimalValue_ShouldPreserveTrailingZeros()
        {
            var invoiceJson = File.ReadAllText("invoice.json");

            var invoice = JsonConvert.DeserializeObject<Invoice>(invoiceJson);

            invoice.Should().NotBeNull();
            invoice?.InvoiceLines?[0].VatAmount.ToString(CultureInfo.InvariantCulture).Should().Be("0.00");
        }
    }
@elgonzo
Copy link

elgonzo commented Jan 3, 2023

Duplicate of #2768.

The author of Newtonsoft.Json has already committed a fix to the repository, and should likely land with the next Newtonsoft.Json version...

@Alperen2558
Copy link
Author

Alperen2558 commented Feb 15, 2023

Hi again @elgonzo. When is the next planned release for version 13.0.3? We are a bit dependent on this fix.

@elgonzo
Copy link

elgonzo commented Feb 15, 2023

@Alperen2558 i can't tell because i am not associated nor involved in any way with the Newtonsoft.Json project. That's a question only the author of Newtonsoft.Json can give an answer to...

@Alperen2558
Copy link
Author

Hi @JamesNK. Do you have any rough estimation of the time for your next release for version 13.0.3?

@JamesNK
Copy link
Owner

JamesNK commented Feb 16, 2023

13.0.3-beta1 is already on NuGet. You can use it now. If you require a final version then I don't have an exact date. Maybe in a few weeks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants