eclipse-ee4j / eclipse-ee4j/jersey

FreeMarker & model

Open
#3,353 3 comments 0 reactions 0 assignees View on GitHub
Priority: Minor Type: Improvement
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

Regarding FreeMarker integration, the guide says:

> Jersey will assign the model instance to an attribute named model.

This translates in FreemarkerViewProcessor to:

```
Object model = viewable.getModel();
if (!(model instanceof Map)) {
model = new HashMap() {{
put("model", viewable.getModel());
}};
}
Charset encoding = setContentType(mediaType, httpHeaders);

template.process(model, new OutputStreamWriter(out, encoding));
```

I do not understand why non-Map objects are first wrapped in a HashMap, as FreeMarker is able to [directly take in many types of objects](http://freemarker.org/docs/api/freemarker/template/Template.html#process-java.lang.Object-java.io.Writer-).

Without this, if I use a POJO for example, I would be able to access the field foo directly in my .ftl as ${foo} rather than ${model.foo} as is the case now.

Appreciate your advice/comments on this please. Thank you!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.