diff --git a/common/src/main/java/dev/cel/common/values/BaseProtoCelValueConverter.java b/common/src/main/java/dev/cel/common/values/BaseProtoCelValueConverter.java index 3310b3dad..ef45a622b 100644 --- a/common/src/main/java/dev/cel/common/values/BaseProtoCelValueConverter.java +++ b/common/src/main/java/dev/cel/common/values/BaseProtoCelValueConverter.java @@ -158,13 +158,20 @@ private ListValue adaptJsonListToCelValue(com.google.protobuf.ListValu .collect(toImmutableList())); } - // TODO: Investigate changing MapValue key to StringValue - private MapValue adaptJsonStructToCelValue(Struct struct) { + private MapValue adaptJsonStructToCelValue( + Struct struct) { return ImmutableMapValue.create( struct.getFieldsMap().entrySet().stream() .collect( toImmutableMap( - e -> fromJavaObjectToCelValue(e.getKey()), + e -> { + CelValue key = fromJavaObjectToCelValue(e.getKey()); + if (!(key instanceof dev.cel.common.values.StringValue)) { + throw new IllegalStateException( + "Expected a string type for the key, but instead got: " + key); + } + return (dev.cel.common.values.StringValue) key; + }, e -> adaptJsonValueToCelValue(e.getValue())))); }