-
Notifications
You must be signed in to change notification settings - Fork 391
Add AbbreviatedUnitsConverter for Json.NET #985
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
Add AbbreviatedUnitsConverter for Json.NET #985
Conversation
.. with tests based on the SerializationTestsBase - no change to the DefaultDataContractJsonSerializerTests: only added Serializataion/Deserialization #regions
- added two tests ensuring the compatibility with a PlainOldQuantity (JsonObject)
I'm getting around to this one, soon. |
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.
Impressive suite of tests 👏
Some minor feedback.
} | ||
|
||
[Fact] | ||
public void DoubleQuantity_InScientificNotation_SerializedWithExpandedValueAndAbbreviatedUnit() |
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.
I'm not sure what this test verifies on our JsonNet serialization implementation?
Scientific notation on the ctor argument is simply a regular double
so I believe this tests pretty much overlaps with DoubleQuantity_SerializedWithDoubleValueAndAbbreviatedUnit
.
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.
Same with the below test.
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 same tests exist in DataContractSerializerTests and DefaultDataContractJsonSerializerTests. I think I'll remove them there as well.
I'm surprised that I couldn't find the inverse set of tests - but from memory, both DC & JsonNet also support 1E+9 as input.
UnitsNet.Serialization.JsonNet.Tests/AbbreviatedUnitsConverterTests.cs
Outdated
Show resolved
Hide resolved
UnitsNet.Serialization.JsonNet.Tests/AbbreviatedUnitsConverterTests.cs
Outdated
Show resolved
Hide resolved
…ndedValueAndAbbreviatedUnit - added a test for Mbar/mbar: DoubleIQuantity_DeserializedFromDoubleValueAndAbbreviatedUnit_CaseSensitiveUnits - added an example to AbbreviatedUnitsConverter xml doc
.. with tests based on the SerializationTestsBase
With the default settings matches all properties and values using the StringComparer.OrdinalIgnoreCase comparer (as is the default JsonNet matching strategy).
It is possible to customize the 'known types' information (defaults to
Quantity.ByName
) - however don't expect to have out of the box handling forHowMuch
just yet - we're still dependent on the switch inQuantity.From
(we should maybe consider introducing construction methods into QuantityInfo sub-classes or something).I managed to get the decimals working with manually operating the reader (not without a few hurtles).
Finally, another break from the original serialization converters (but consistent with the DataContract / protobuf) is handling of the default types (instead of throwing an exception when no value is provided).
PS I haven't added any handling for EmitDefaultValues = false (I assume there is one such option somewhere in JsonNet) - but I think that's hardly necessary (if we want it- we should discuss the 'default' behavior of the
Type
property)