jsonspring-mvcspring-roogvnix

How converts list objects to JSON in gvnix


Hi I´m developing new controllers over GVNIX development tool but I don´t understand how it is transforming object list to JSON.

I have seen in the GEO example, the entities list are working with DataTables and the ajax filter it´s working with JSON. The database access are in BatchService that returns object list, but I havent found where the controller get´s this list and returns the JSON.

Can anybody help me to understand how it´s working ?

Thanks


Solution

  • The conversion is handle by Spring Web MVC based on @RequestMapping and @ResponseBody annotations value through Jaskson Library. (This post talk about it)

    In addition, as standard Spring MVC Jackson converter doesn't use the ApplicationConversionService Bean, gvNIX includes a custom converter that uses this bean to serialize and bind some object (as Spring do in standard POST request). You can found this configuration in webmvc-config.xml file:

    <bean class="org.gvnix.web.json.Jackson2RequestMappingHandlerAdapter" 
        id="dataBinderRequestMappingHandlerAdapter" p:order="1">
            <property name="objectMapper">
                <bean class="org.gvnix.web.json.ConversionServiceObjectMapper"/>
            </property>
    </bean>
    

    Note: Jackson2RequestMappingHandlerAdapter only handles request which @RequestMapping propierties produces and consumes is set to application/json

    Good luck!