I tried using both flexjson.JSONSerializer and com.fasterxml.jackson.databind.ObjectMapper in a freemarker template to convert a csv file loaded via the csv data loader csv(menu.csv, {trimCells: true}) to JSON.
When I try to run this, I get the following exception:
...
Caused by: java.lang.UnsupportedOperationException: Operation supported only on TemplateHashModelEx. fmpp.models.CsvSequence does not implement it though.
at freemarker.ext.beans.HashAdapter.getModelEx(HashAdapter.java:186)
at freemarker.ext.beans.HashAdapter.access$000(HashAdapter.java:38)
at freemarker.ext.beans.HashAdapter$1.iterator(HashAdapter.java:99)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:696)
... 46 common frames omitted
I don't know any of the internals of FreeMarker (yet), but this looks to me like the CsvSequence does implement the freemarker.template.TemplateHashModel but not freemarker.template.TemplateHashModelEx.
The only place I found getModelEx is in the HashAdaptor, so I assume that it uses the newer interface for hashs.
Any idea how to solve this?
The
CsvSequenceimplements bothfreemarker.template.TemplateHashModelandfreemarker.template.TemplateSequenceModel, see http://fmpp.sourceforge.net/api/fmpp/models/CsvSequence.htmlAs I want to convert only the sequence, not the headers, I can simply convert the
CsvSequenceto a normal sequence e.g. like this:or