Skip to content

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

Merged

Conversation

lipchev
Copy link
Collaborator

@lipchev lipchev commented Nov 8, 2021

.. 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 for HowMuch just yet - we're still dependent on the switch in Quantity.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)

.. 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)
@angularsen
Copy link
Owner

I'm getting around to this one, soon.

Copy link
Owner

@angularsen angularsen left a 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()
Copy link
Owner

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.

Copy link
Owner

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.

Copy link
Collaborator Author

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.

…ndedValueAndAbbreviatedUnit

- added a test for Mbar/mbar: DoubleIQuantity_DeserializedFromDoubleValueAndAbbreviatedUnit_CaseSensitiveUnits
- added an example to AbbreviatedUnitsConverter xml doc
@angularsen angularsen changed the title Implemented the AbbreviatedUnitsConverter (JsonNet) Add AbbreviatedUnitsConverter for Json.NET Nov 20, 2021
@angularsen angularsen merged commit 1584f1c into angularsen:master Nov 20, 2021
@angularsen
Copy link
Owner

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

Successfully merging this pull request may close these issues.

2 participants