Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class com.google.template.soy.data.internal.SoyMapImpl cannot be cast to class com.google.template.soy.data.SoyLegacyObjectMap #223

Open
lpellegr opened this issue Dec 28, 2020 · 0 comments

Comments

@lpellegr
Copy link

lpellegr commented Dec 28, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant