Automatically serializing/deserializing decimal to string

27 views
Skip to first unread message

Idsa

unread,
Mar 19, 2018, 7:01:11 PM3/19/18
to RavenDB - 2nd generation document database
When you're trying to save a document containing a decimal property, you get an error message suggesting to store decimal as string. Is there an automatic way to do that both for werialisation and deserialisation (i. e. convention, attribute, etc.)?

Oren Eini (Ayende Rahien)

unread,
Mar 20, 2018, 2:19:20 AM3/20/18
to ravendb
You can use document.Convention.CustomizeJsonSerializer and the register a JsonConverter for that.
But decimals (in the range that that is supported by JSON) should just work 

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


On Tue, Mar 20, 2018 at 1:01 AM, Idsa <alex...@gmail.com> wrote:
When you're trying to save a document containing a decimal property, you get an error message suggesting to store decimal as string. Is there an automatic way to do that both for werialisation and deserialisation (i. e. convention, attribute, etc.)?

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexander Sidorov

unread,
Mar 23, 2018, 1:14:29 PM3/23/18
to rav...@googlegroups.com
Is the range supported by Json compatible with decimal in C#? I process trades from crypto exchanges and regularly get this error while trying to save decimal values to RavenDb. Does RavenDb store doubles? Currently I store string which is problematic when I'd like to query things

--
You received this message because you are subscribed to a topic in the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/MOxfeC8-bhI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ravendb+unsubscribe@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Mar 23, 2018, 1:17:18 PM3/23/18
to ravendb
RavenDB can handles numbers of any precision you want.
Internally, we store a double in its string state, so the precision is exact.

The problem happens when you want to: Query or use JS on it on the server side.
For JS scripts, numbers are always doubles. 
For querying, we use double as the fractional type.

Alexander Sidorov

unread,
Mar 23, 2018, 1:23:57 PM3/23/18
to rav...@googlegroups.com
So why do I get an exception trying to save some decimal then? Could it be a bug?

Oren Eini (Ayende Rahien)

unread,
Mar 23, 2018, 1:25:27 PM3/23/18
to ravendb
What is the exact client version you are using?

Alexander Sidorov

unread,
Mar 23, 2018, 1:26:17 PM3/23/18
to rav...@googlegroups.com
4.0.0 on Mac

Oren Eini (Ayende Rahien)

unread,
Mar 23, 2018, 1:27:03 PM3/23/18
to ravendb
Try using 4.0.3, we fixed this issue, IIRC

Alexander Sidorov

unread,
Mar 23, 2018, 1:36:11 PM3/23/18
to rav...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages