Skip to content

Commit

Permalink
Fix numeric types with less than 32 bits are wrong
Browse files Browse the repository at this point in the history
This adds additional unit tests for numeric types when using the
Generic Object Serializer.

Numeric types with less than 32 bits currently fail. This includes:
- Enum U8
- Enum U16
- U8
- U16
- I8
- I16

These tests fail because the serializer assumes that type information
is maintained by JSONtext when parsing from JSON. This, however, is
not the case with certain numeric types, for which the parser always
returns 32-bit values, no matter which input type is specified.

When the 32-bit value is later combined with the type information of
a type with less bits, the lower bits are truncated, which results in
incorrect values.

Note that 64-bit values are not affected because they are handled in
native bitness by JSONtext.

Fixed by changing the minimum required version for JSONtext to 1.6.7,
which returns the correct bitness for all numeric types.

References #22
  • Loading branch information
logmanoriginal committed May 27, 2022
1 parent 4980f86 commit 4455976
Show file tree
Hide file tree
Showing 37 changed files with 297 additions and 8 deletions.
16 changes: 8 additions & 8 deletions .vipb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<VI_Package_Builder_Settings Version="2018" Created_Date="2021-03-19 22:45:16" Modified_Date="2022-04-23 17:44:10" Creator="Pascal Neuperger" Comments="" ID="5a43a13c055b83d65b60f5a05381030b">
<VI_Package_Builder_Settings Version="2018" Created_Date="2021-03-19 22:45:16" Modified_Date="2022-05-27 09:35:25" Creator="Pascal Neuperger" Comments="" ID="bf89c7502e3241fb05f5383352876c1d">
<Library_General_Settings>
<Package_File_Name>PNR_lib_JSONtext_Object_Serialization</Package_File_Name>
<Library_Version>1.0.2.24</Library_Version>
<Library_Version>1.0.3.25</Library_Version>
<Auto_Increment_Version>false</Auto_Increment_Version>
<Library_Source_Folder>.</Library_Source_Folder>
<Library_Output_Folder>..</Library_Output_Folder>
Expand All @@ -17,11 +17,11 @@
</Library_General_Settings>
<Advanced_Settings>
<Package_Dependencies>
<External_Dependencies>jdp_science_jsontext &gt;= 1.5.4.98</External_Dependencies>
<External_Dependencies>jdp_science_lib_common_utilities &gt;= 1.2.2.13</External_Dependencies>
<External_Dependencies>jdp_science_jsontext &gt;= 1.6.7.107</External_Dependencies>
<External_Dependencies>jdp_science_lib_common_utilities &gt;= 1.4.0.17</External_Dependencies>
<External_Dependencies>pnr_lib_labview_composition &gt;= 1.2.3.18</External_Dependencies>
<Direct_Dependencies>jdp_science_jsontext-1.5.4.98</Direct_Dependencies>
<Direct_Dependencies>jdp_science_lib_common_utilities-1.2.2.13</Direct_Dependencies>
<Direct_Dependencies>jdp_science_jsontext-1.6.7.107</Direct_Dependencies>
<Direct_Dependencies>jdp_science_lib_common_utilities-1.4.0.17</Direct_Dependencies>
<Direct_Dependencies>pnr_lib_labview_composition-1.2.3.18</Direct_Dependencies>
</Package_Dependencies>
<Custom_Action_VIs>
Expand All @@ -47,7 +47,7 @@ Only serializes classes that inherit from JSON Serializable that defines methods
<Copyright>Copyright (c) 2021-2022, Pascal Neuperger</Copyright>
<Packager>Pascal Neuperger</Packager>
<URL>https://github.com/LogMANOriginal/JSONtext-Object-Serialization</URL>
<Release_Notes>- [#21] Fixed an issue in "Generic Object Serializer" that resulted in an error when attempting to de-serialize a class without data member using inline type name handling.</Release_Notes>
<Release_Notes>- [#22] Changed minimum required version for JSONtext to 1.6.7. That version addresses an issue which resulted in incorrect values for numeric types with less than 32 bits.</Release_Notes>
</Description>
<Destinations>
<Toolkit_VIs>
Expand Down Expand Up @@ -299,7 +299,7 @@ Only serializes classes that inherit from JSON Serializable that defines methods
<Path>JSON Serializable Serializer Constant.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>4B4687354A4399285DA6A1543BF62B09</GUID>
<GUID>7EBFDF826A4235191D26058A74809687</GUID>
</Functions_Palette_Data>
</Library_Palette_Definition>
</VI_Package_Builder_Settings>
Expand Down
Binary file modified .vipc
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<Item Name="Dictionary.lvclass" Type="LVClass" URL="../Dictionary/Dictionary.lvclass"/>
<Item Name="Create Dummy Country Data.vi" Type="VI" URL="../Create Dummy Country Data.vi"/>
<Item Name="No Data Member Subclass.lvclass" Type="LVClass" URL="../No Data Member Subclass/No Data Member Subclass.lvclass"/>
<Item Name="Numeric Types.lvclass" Type="LVClass" URL="../Numeric Types/Numeric Types.lvclass"/>
</Item>
<Item Name="Type Name Handling.lvlib" Type="Library" URL="../Type Name Handling/Type Name Handling.lvlib"/>
<Item Name="LabVIEW Extensions.lvlib" Type="Library" URL="../LabVIEW Extensions/LabVIEW Extensions.lvlib"/>
Expand Down Expand Up @@ -51,4 +52,15 @@
<Item Name="JSON to LVObject - Object with Array of Objects - Returns Object.vi" Type="VI" URL="../JSON to LVObject - Object with Array of Objects - Returns Object.vi"/>
<Item Name="JSON to LVObject - Object with Array of Cluster with Object - Returns Object.vi" Type="VI" URL="../JSON to LVObject - Object with Array of Cluster with Object - Returns Object.vi"/>
<Item Name="JSON to LVObject - Dictionary of Object with Array of Objects - Returns Object.vi" Type="VI" URL="../JSON to LVObject - Dictionary of Object with Array of Objects - Returns Object.vi"/>
<Item Name="JSON to LVObject - U16 Enum Member - Should Parse Value.vi" Type="VI" URL="../JSON to LVObject - U16 Enum Member - Should Parse Value.vi"/>
<Item Name="JSON to LVObject - U32 Enum Member - Should Parse Value.vi" Type="VI" URL="../JSON to LVObject - U32 Enum Member - Should Parse Value.vi"/>
<Item Name="JSON to LVObject - U8 Enum Member - Should Parse Value.vi" Type="VI" URL="../JSON to LVObject - U8 Enum Member - Should Parse Value.vi"/>
<Item Name="JSON to LVObject - U8 Member - Should Parse Value.vi" Type="VI" URL="../JSON to LVObject - U8 Member - Should Parse Value.vi"/>
<Item Name="JSON to LVObject - U16 Member - Should Parse Value.vi" Type="VI" URL="../JSON to LVObject - U16 Member - Should Parse Value.vi"/>
<Item Name="JSON to LVObject - U32 Member - Should Parse Value.vi" Type="VI" URL="../JSON to LVObject - U32 Member - Should Parse Value.vi"/>
<Item Name="JSON to LVObject - U64 Member - Should Parse Value.vi" Type="VI" URL="../JSON to LVObject - U64 Member - Should Parse Value.vi"/>
<Item Name="JSON to LVObject - I8 Member - Should Parse Value.vi" Type="VI" URL="../JSON to LVObject - I8 Member - Should Parse Value.vi"/>
<Item Name="JSON to LVObject - I16 Member - Should Parse Value.vi" Type="VI" URL="../JSON to LVObject - I16 Member - Should Parse Value.vi"/>
<Item Name="JSON to LVObject - I32 Member - Should Parse Value.vi" Type="VI" URL="../JSON to LVObject - I32 Member - Should Parse Value.vi"/>
<Item Name="JSON to LVObject - I64 Member - Should Parse Value.vi" Type="VI" URL="../JSON to LVObject - I64 Member - Should Parse Value.vi"/>
</Library>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
277 changes: 277 additions & 0 deletions Generic Object Serializer Tests/Numeric Types/Numeric Types.lvclass

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 4455976

Please sign in to comment.