Repository navigation
Allow a custom "__type" name in the JsonExporter lambda converters - #1255
Merged
Merged
Conversation
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>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #877.
The
addConverter()overloads that take a user lambda always usedBT::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>()andBT_JSON_CONVERTERalready let you choose the name.type_nameparameter on both lambda overloads; empty keeps the demangled name."__type". The from_json overload registers it forfromJson()in addition to the demangled name, so existing JSON keeps working.(lambda, const char*)to_json overload forwards withadd_type = true. Without it,addConverter<T>(f, "Name")would silently convert the literal tobool 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