class com.google.template.soy.data.internal.SoyMapImpl cannot be cast to class com.google.template.soy.data.SoyLegacyObjectMap
lpellegr opened this issue · 0 comments
Let's say you have a use case with a param x
of type map<string, ?>
. This map includes other nested maps as value. Now, assume you need to access x['field1']['field2']
for instance. This does not work out of the box.
Looking at the source code, I tried to mark nested maps as SoyMap with com.google.template.soy.data.SoyValueConverter.markAsSoyMap
. Unfortunately, I am still getting this error message:
Unexpected error occurred: class com.google.template.soy.data.internal.SoyMapImpl cannot be cast to class com.google.template.soy.data.SoyLegacyObjectMap (com.google.template.soy.data.internal.SoyMapImpl and com.google.template.soy.data.SoyLegacyObjectMap are in unnamed module of loader 'app')
java.lang.ClassCastException: class com.google.template.soy.data.internal.SoyMapImpl cannot be cast to class com.google.template.soy.data.SoyLegacyObjectMap (com.google.template.soy.data.internal.SoyMapImpl and com.google.template.soy.data.SoyLegacyObjectMap are in unnamed module of loader 'app')
at mynamespace.Layout.render(mytemplate.soy:68)
Line 68 of the soy template contains <div class="container">{$x['field1']['field2']}</div>
.
Is SoySauce supporting this use case? as a workaround, I am thinking about flattening nested maps or to define a custom function with "variable args" to get access to the nested fields. If indexed access operators are not supposed to be used in a nested context, what is the recommended approach for the best compliance with the future of closure templates?