If your concern is iterating through a non-trivial number of fields, why not use an ObjectMapper
? For example, an org.springframework.web.servlet.view.json.MappingJacksonJsonView
could send JSON data to the UI, and would also keep UI in charge of rendering of that data.
You can pass this to the ``:
<bean id="contentNegotiatingViewResolver"
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"
p:defaultContentType="text/html">
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
<entry key="${mimeKey}" value="${mimeMessageType} />
</map>
</property>
<property name="defaultViews">
<list>
<bean
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"
p:objectMapper-ref="objectMapper" />
<bean class="org.springframework.web.servlet.view.xml.MarshallingView"
p:marshaller-ref="objectMarshaller" />
</list>
</property>
...
</bean>