问题描述:

I have a data element that can either be a Map or a List of Maps.

Here are two simplified data examples (expressed as JSON for readability)

1) Maps

{

"lom:general": {

"lom:title": {"lom:string": {

"language": "fr",

"content": "Premiers Pas avec un Progiciel de Gestion Intégré"

}},

"lom:language": "fr"

},

"lom:technical": {"lom:location": "http://hub11.ecolearning.eu/course/progiciel-metiers-pgi/"}

}

2) List of Maps

{

"lom:general": {

"lom:title": {"lom:string": [

{

"language": "fr",

"content": "DIY Education aux médias et à l'information - 3ed"

},

{

"language": "en",

"content": "DIY Media and Information Literacy - 3ed"

}

]},

"lom:language": [

"fr",

"en"

]

},

"lom:technical": {"lom:location": "http://hub5.ecolearning.eu/course/diy-do-it-yourself/"}

}

I want to check the type of element lom:general.lom:title.lom:string and iterate it if it is a list.

I have tried the following:

<title>

<#assign titles = lom\:general.lom\:title.lom\:string>

<#if titles?is_enumerable>

<#list titles as title>

<string language="${title.language}">${title.content}</string>

</#list>

<#else>

<string language="${titles.language}">${titles.content}</string>

</#if>

</title>

The template works as expected with the first data example. However, the second data example raises a StackOverflowError

java.lang.StackOverflowError

at sun.reflect.misc.ReflectUtil.checkPackageAccess(ReflectUtil.java:188)

at sun.reflect.misc.ReflectUtil.checkPackageAccess(ReflectUtil.java:164)

at sun.reflect.generics.reflectiveObjects.TypeVariableImpl.getGenericDeclaration(TypeVariableImpl.java:164)

at sun.reflect.generics.reflectiveObjects.TypeVariableImpl.equals(TypeVariableImpl.java:189)

at com.sun.beans.TypeResolver.resolve(TypeResolver.java:190)

at com.sun.beans.TypeResolver.resolve(TypeResolver.java:201)

Where the last line is repeated dozens of times

相关阅读:
Top