Skip to content

Question on Json conversion in 4.6 #829

Closed
@benjaminholdennearearth

Description

In 4.5 I could register json conversion functions such as:

void jsonPoint(const geometry_msgs::msg::Point& p, nlohmann::json& j)
{
  j["x"] = p.x;
  j["y"] = p.y;
  j["z"] = p.z;
}
void jsonTime(const rclcpp::Time& t, nlohmann::json& j)
{
  j["stamp"] = t.seconds();
}
void jsonOptionalString(const std::optional<std::string>& s, nlohmann::json& j)
{
    if (s.has_value())
    {
        j["value"] = *s;
    }
    else
    {
        j["value"] = "nullopt";
    }
}

However in 4.6 with the removal of adding custom converters in favor of the macro BT_JSON_CONVERTER I cannot figure out how to replicate this behavior and was wondering:

  1. Was this functionality removed? And was it removed on purpose?
  2. How I can recreate this in 4.6 if it was not removed?

I can only find examples of using the macro with simple structs. I have been reading through the code to try and figure this out, but have not made any progress yet so I figured I would reach out in case there is a simple solution.

Thank you for your time and for all the hard work on this!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions