JKI-JSON-Serialization icon indicating copy to clipboard operation
JKI-JSON-Serialization copied to clipboard

JSON ignoring single variant in a cluster

Open jimkring opened this issue 5 years ago • 3 comments

Example VI: JSON Test ignoring single variant in a cluster.vi.zip

See original bug report on JKI forums.

Notice how the "bridge_data" (variant that's inside the cluster) does not show up in the JSON data.

image

However, we I add another element next to the variant, so it's not the only element in the cluster, then we see "bridge_data" in the JSON string.

image

jimkring avatar Feb 13 '20 15:02 jimkring

It seems to be related to a LabVIEW "feature" that transforms a cluster of one element to the element itself when you flatten it. In this case, it must be interpreting the variant as matching the cluster instead of the first element of the cluster.

francois-normandin avatar Feb 13 '20 18:02 francois-normandin

@jimkring I found the error to originate in the "JSON Serializer.lvclass:Cluster Info.vi" which calls the OpenG "Array to VData" method. This OpenG method errors out when the payload is not a cluster. When it is a cluster, it extracts the elements instead of returning a 1-element array containing the variant.

This seems like a LabVIEW bug to me... and it has to do with type propagation. I was able to reproduce a very fundamental inconsistency as shown here.

https://www.youtube.com/watch?v=XevSM1Bj4l4

I will report this bug in a well documented way to NI, but I thought I'd drop it here because this is the cause of the problem. Once I had propagation correct, I was able to get the cluster of an empty variant to show up as a single-element variant inside a cluster (not shown here).

francois-normandin avatar Feb 14 '20 13:02 francois-normandin

Thanks @francois-normandin. I've also posted more info here on the JKI JSON forum, a bug report on LAVA, and I've let NI know. The fix is for users to add a To Variant function before calling Flatten to JSON String, since the bug is in the coercion dot.

jimkring avatar Feb 14 '20 16:02 jimkring