eclipse-ee4j / jersey

Eclipse Jersey Project - Read our Wiki:
https://github.com/eclipse-ee4j/jersey/wiki
Other
691 stars 352 forks source link

FreeMarker & model #3353

Open jerseyrobot opened 8 years ago

jerseyrobot commented 8 years ago

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<String, Object>() {{
        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.

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!

jerseyrobot commented 6 years ago
jerseyrobot commented 8 years ago

@glassfishrobot Commented Reported by Revarye

jerseyrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA JERSEY-3081