Skip to content

Allow a custom "__type" name in the JsonExporter lambda converters - #1255

Merged
facontidavide merged 1 commit into
masterfrom
fix/json-converter-type-name
Oct 24, 2026
Merged

facontidavide merged 1 commit into
masterfrom
fix/json-converter-type-name

Conversation

@facontidavide

Copy link
Copy Markdown
Collaborator

Fixes #877.

The addConverter() overloads that take a user lambda always used BT::demangle(typeid(T)) as the JSON "__type", e.g. geometry_msgs::msg::Pose_<std::allocator<void> >. That name is verbose and compiler-specific. addConverter<T>() and BT_JSON_CONVERTER already let you choose the name.

  • Optional trailing type_name parameter on both lambda overloads; empty keeps the demangled name.
  • The to_json overload writes it in "__type". The from_json overload registers it for fromJson() in addition to the demangled name, so existing JSON keeps working.
  • A (lambda, const char*) to_json overload forwards with add_type = true. Without it, addConverter<T>(f, "Name") would silently convert the literal to bool add_type.

API: new defaulted parameters on inline templates plus one new inline overload. Source compatible, no ABI impact.

Test: JsonTest.CustomTypeName.

🤖 Generated with Claude Code

The addConverter() overloads that take a user lambda always wrote and
registered BT::demangle(typeid(T)) as the JSON "__type", e.g.
"geometry_msgs::msg::Pose_<std::allocator<void> >". addConverter<T>() and
BT_JSON_CONVERTER already let the user choose the name, but the lambda
overloads did not, so such JSON was verbose, compiler-specific, and could
not use language-neutral type names.

Add an optional trailing type_name parameter (empty keeps the demangled
name). The to_json overload writes it in "__type", the from_json overload
registers it in the type-name lookup used by fromJson(), in addition to
the demangled name, so existing JSON keeps working.

A to_json overload taking only (lambda, const char*) forwards with
add_type = true; without it, addConverter<T>(f, "Name") would silently
convert the string literal to bool add_type.

Fixes #877

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@facontidavide
facontidavide merged commit 7441d8d into master Oct 24, 2026
16 checks passed
@facontidavide
facontidavide deleted the fix/json-converter-type-name branch October 24, 2026 15:02
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow custom type names in JSONExporter

1 participant