Hi everyone,
I've created a Java utility for mapping between Protobuf messages using
simple rules and selecting nested data using string paths (like "a.b.c",
map["key"], struct.key).
*What it does:*
- *Selector:* Retrieve data using a path string (e.g.,
valueHandler.getValue(msg, "profile.address[\"home\"].zip_code")). Handles
nested fields, maps, structs, and unwraps google.protobuf.Value.
- *Mapper:* Map between different proto messages using rules like:
Java
List<String> rules = Arrays.asList(
"target_field = source.field",
"target_list += source_item", // Append
"target_map[\"key\"] = source_value", // Map put
"-field_to_delete" // Delete
);
Message target = protoMapper.map(sourceMsg, Target.getDescriptor(),
rules);
*Why?* I initially built this for a pipeline mapping step to reduce
boilerplate code. It ended up handling quite a few edge cases around type
conversion, path resolution, literals, and dynamic message handling.
*Question:* Would a utility like this be useful to others? Are there
established Java libraries that provide this specific rule-based mapping
and deep path selection beyond standard reflection or FieldMask projections?
It started as a quick selector but grew more complex. I'm considering
making it a standalone library if there's interest.
The current code (WIP) is here:
https://github.com/krickert/micronaut-multiproject-example/tree/main/protobuf-models/src/main/java/com/krickert/search/model/mapper
Thanks for any feedback!
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/protobuf/07bddb2f-6c5e-4a82-9b9f-c6aaf6f1dbc6n%40googlegroups.com.