question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default date serialization drops trailing zeros in the microseconds date portion.

See original GitHub issue

Hello,

I picked this problem up when I was parsing a date serialized by newtonsoft in another system.

I have a date from my source (.net system) as follows:

2017-11-21 05:55:27.064100

When this date is serialized by newtonsoft it comes out like this:

{"DateCreated":"2017-11-21T05:55:27.0641"}

Note the trailing zeros were truncated. This breaks deserialization which is expecting microseconds in my java app using this format specifier: “yyyy-MM-dd’T’HH:mm:ss.SSSSSSX”

I expect date to be serialized like this: {"DateCreated":"2017-11-21T05:55:27.064100"}

I have attached code to reproduce. newtonsoft-date-issue.zip

Thanks,

Avner

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tmeniercommented, Nov 29, 2017

I just discovered this myself. Truncating those 0’s also compromises sortability of the default date format.

I understand this is just a default and it is easy to override, but does anyone have any historical perspective on how this decision was reached? (I wanted to mimic Json.NET’s default date serialization behavior in a library of my own, assuming it represents best practices, but now I’m not so sure.)

0reactions
Eli-Black-Workcommented, Dec 23, 2022

After some thought, I think that the current default is probably best, and if we need datetimes that are sortable/comparable, we should override the time format string. See https://github.com/JamesNK/Newtonsoft.Json/issues/2780#issuecomment-1363704872 for more details 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ending 0's are getting truncated from millisecond part of ...
This issue is caused by the fact that Jackson by default uses Java's built-in DateTimeFormatter to serialize and deserialize dates and times ...
Read more >
83989: Timestamp.toString() truncates trailing zeros in ...
In my case the MySql column is specified "timestamp datetime(3) DEFAULT NULL", and the result of .toString is typically "yyyy-mm-dd hh:mm:ss.fff ...
Read more >
Keep trailing zeros on Timestamp SELECT
This is the issue: I am reading rows with a timestamp column from a table and I need to make sure that the...
Read more >
DateTime and DateTimeOffset support in System.Text.Json
If the round-trip format representation of a DateTime or DateTimeOffset instance has trailing zeros in its fractional seconds, then ...
Read more >
DateTime in chrono - Rust
Parses a string from a user-specified format into a DateTime<FixedOffset> value, and a slice with the remaining portion of the string. Note that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found