It reminds me of CEL (https://cel.dev/), which is used by the protovalidate 
project (https://github.com/bufbuild/protovalidate) but can also be used 
standalone to accomplish some of the things you're doing.

Gary

On Wednesday, April 23, 2025 at 1:56:14 PM UTC+2 Kristian Rickert wrote:

> 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/46dd07bb-da92-4e43-be2e-b9d29ce639a0n%40googlegroups.com.

Reply via email to