понедельник, 10 августа 2015 г.

GWT 2.7.0. Deserialize json on server with Autobean framework

One can use JSON libraries to deserialize json to POJO. How to do it with GWT?

GWT ships with Autobean framework. It allows you to serialize the json on client. But, we can use it on the server side too.

Here is the magic:
1) define the the interface which extends the AutoBeanFactory
2) on the server side use beanFactory = AutoBeanFactorySource.create(Your_Factory_class.class);

AutoBeanFactorySource is in com.google.web.bindery.autobean.vm.AutoBeanFactorySource package. One clue is that it is experimental. So check how it is working in your environment.

3) To decode json to POJO use:
AutoBean<Your_POJOInterface> bean = AutoBeanCodex.decode(
                    beanFactory, Your_POJOInterface.class, jsonString);
Your_POJOInterface requestObject = bean.as();

4) That is all! Just plain GWT and no other special mappers!

Комментариев нет:

Отправить комментарий