Hi,
I'd like to serialize a DynamicData sample to JSON/XML using the Modern C++ APIs.
I realize there are internal APIs: DDS_DynamicDataFormatter_to_xml and DDS_DynamicDataFormatter_to_json. But, these APIs seem to take DDS_DynamicData types as arguments. Is there an equivalent API for the Modern C++ DynamicData type ? Thanks!
Hi Kang,
RTI Connext DDS 5.3.0 introduced a public APIs to transform DDS samples into XML or JSON. You can use these APIs with both DynamicData and IDL-generated types.
In the case of the Modern C++ API you will have to use
rti::topic::to_string
, which is documented here. Here is an example on how to transform a sample into JSON:Let me know if this works for you.
Thanks,
Fernando.
This is excellant. I didn't realize this was added to 5.3.0. Thanks for your help Fernando!
This would be great to have for someone using 5.2.3... Any way around it for us stuck on older versions? (Using Java on my end).
Is there any similar API in Java to print received DDS sample in Json or XML format. ?
C++ std::string str = rti::topic::to_string(sample, rti::topic::PrintFormatProperty::Json());