Hi
I have a question on how to define multiple types in XML format for a complicated (nested) json data, which has multiple array dimensions and data types. The json sample is attacted for your reference.
Tried to define the types like the XML code below, but when publishing it by web integration service to a certain database, blank arrays are created without any values, which makes the read data larger than the written one. So,
- In the original data, 'Value' has multiple data types like: string, integer, float, long, etc. How shall its type definition be?
- 'Parameter' has arrays in 2, 3, 4 dimensions, if set as arrayDimensions="4", after publishing to the data reader, all arrays will be in 4 demensions with several vacant 'name', 'unit' and 'value'. Is there any way to set the exact dimensions for this 'Parameter'?
<types>
<struct name="Type1">
<member id="0" name="Name" type="string" />
<member id="1" name="Unit" type="string" />
<member id="2" name="Value" type="string" />
</struct>
<struct name="Type2">
<member id="0" name="Name" stringMaxLength="255" type="string" />
<member id="1" name="Parameter" arrayDimensions="4" type="nonBasic" nonBasicTypeName="Type1" />
</struct>
<struct name="Type3">
<member id="0" name="Name" type="string" />
<member id="1" name="ParameterGroup" arrayDimensions="3" type="nonBasic" nonBasicTypeName="Type2" />
</struct>
</types>
Attachment | Size |
---|---|
json_sample.txt | 993 bytes |
Yanyang,
My name is Christopher Carson and I am the RTI Field Applications Engineer that works with GE Healthcare globally. Can you reach out to me directly so I can help you with your inquiry? You may contact me at chris@rti.com or phone me at +1 (773) 332-0402. I am located in USA Central Standard Time should you chose to phone.
Hi Yanyang,
I will try to answer your questions in reverse order:
This is because you are defining the type as an "array" which by definition always has the same number of elements. If you want to have a variable size (i.e. sometimes 2 sometimes 3, etc.) then you need to use a "sequence" instead of an array. So instead of:
Do this:
Regarding.
The normal way to support members that can be of different data types is to use a union type. For example:
Looking a the JSON file you provided, I would define the types in XML along the lines shown in the attached file.
Hi Gerardo,
Thank you very much for your solution.
For the variable size, replacing 'arrayDimensions' with 'sequenceMaxLength' does solve the problem. It makes data stored subsribed by database is identical with the data published by web integration service.
However, for the 'Value' with multiple data type issue, I tried with your union type, but it did not work as expected:
{"code": "INVALID_INPUT", "message": "rti::webdds::dds::DataWriter::set_dynamic_data_member:Error setting dynamic data member Value
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
"}422 1.003
FYI, the two DDS service version in our system is:
/opt/rti_connext_dds-5.3.0/bin/../resource/app/bin/x64Linux2.6gcc4.1.1/rtiwebintegrationservice
/opt/rti_connext_dds-5.3.1/bin/../resource/app/bin/x64Linux2.6gcc4.1.1/rtirtc_postgresql
Do you happen to know how to solve this set_dynamic_data_member:Error ?
Thanks a lot.
Hi Yanyang,
Could you share with us the POST request that is triggering that error?
Gerardo's example uses a Union to represent all the possible types the value property can hold. In that case, when you POST a new value of a certain type, you need to specify the specific union member you are selecting; that is,
boolean_value
,integer_value
,float_value
, orstring_value
.Following the syntax to represent DDS Unions in JSON, you would need to write your integer value as follows:
Likewise, to write a float value you would need to do:
From your description, I understand you want to be able to POST a sample where the value property of a JSON object can be boolean integer, a string, or a float. That is, something you would represent in JSON Schema as:
With that syntax, all the following examples would be valid syntax:
That is something that cannot be directly represented with the JSON syntax Web Integration Service generates. As Gerardo mentioned Unions would provide you with something similar in principle, a type that can hold samples of different types, but still need you to specify which member you are using in each corresponding case.
Let me know if this helps.
Thanks!
Fernando