[Geoserver-devel] [JIRA] (GEOS-10218) GetFeatureInfo documentation example template generates invalid JSON

Bingen Galartza Iparragirre created an issue

GeoServer / BugGEOS-10218

GetFeatureInfo documentation example template generates invalid JSON

Issue Type:

BugBug

Affects Versions:

2.19.2

Assignee:

Unassigned

Components:

Documentation

Created:

30/Aug/21 1:38 PM

Priority:

LowestLowest

Reporter:

Bingen Galartza Iparragirre

The sample template in the GetFeatureInfo Geojson templating documentation might generate invalid JSON output.

The condition for adding the comma separators is not good enough, as it might add a comma when the next attribute is a geometry. That will make some json parsers to crash. A simple fix would be to use filter instead of iffor skipping the geometry attributes. The Freemarker documentation says the following:

If you need to skip certain element in a list, it’s generally a bad idea to use if directive for that, because then <#sep>, item?has_next, item?counter, item?index, item?item_parity, etc., will not be usable, as FreeMarker doesn’t know what items were and will be actually displayed. Instead, you should try to remove the unwanted items from the sequence that you will list, and then list it (since 2.3.29). Here are some typical examples with and without if.

So, I suggest to change the properties part of the example from this:

Unable to find source-code formatter for language: text. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml

 &lt;#list feature.attributes as attribute2&gt;
 &lt;#if !attribute2.isGeometry&gt;
 "${attribute2.name}": "${attribute2.value}"
 &lt;/#if&gt;
 &lt;#if attribute2_has_next &amp;&amp; !attribute2.isGeometry&gt;
 ,
 &lt;/#if&gt;
 &lt;/#list&gt;

to this:

Unable to find source-code formatter for language: text. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml

&lt;#list feature.attributes?filter(a -&gt; !a.isGeometry) as attribute&gt;
       "${attribute.name}": "${attribute.value}"
       &lt;#if attribute_has_next&gt;
        ,
       &lt;/#if&gt;
     &lt;/#list&gt;

Add Comment

Add Comment

Get Jira notifications on your phone! Download the Jira Cloud app for Android or iOS


This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100175-sha1:61f0814)

Atlassian logo