Friday, July 1, 2011

Re: POJO to JSON

our CTO wants to generate jpa stuff, can you bring some articles on how to do stuff with xtext?

On Fri, Jul 1, 2011 at 1:55 AM, dd <cafebab3@googlemail.com> wrote:
### AutoBeans can be used on client *and* server side:

  static interface MyAutoBeanFactory extends AutoBeanFactory {

    AutoBean<MyPojo> login();

  }


  // In non-GWT code, use AutoBeanFactoryMagic.create(MyFactory.class);

  static final MyAutoBeanFactory FACTORY = GWT.create(MyAutoBeanFactory.class);



  public MyPojo getMyPojo(String json) {

    AutoBean<MyPojo> bean = AutoBeanCodex.decode(FACTORY, MyPojo.class, json);

    return bean.as();

  }


  public String getJson(MyPojo myPojo) {

    AutoBean<MyPojo> bean = AutoBeanUtils.getAutoBean(myPojo);

    return AutoBeanCodex.encode(bean).getPayload();

  }



### JSON Overlay types work on client side only (look at the native javascript code /*-{ }-*/):


  public final native T getPojo(String json) /*-{

    return eval(json); // eval('(' + json + ')');

  }-*/;


  public String getJson(T pojo) {

    return new JSONObject(pojo).toString();

  }



### RequestFactory is great above persistence layers like JPA (and uses AutoBeans under the hood!) but has a lot of boilerplate code.

### Btw: I generate the RequestFactory + JPA stuff with Xtext + Xpand (using a domain specific language (dsl) for my domain model).



- Daniel

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/Lqd-Ks2atkUJ.

To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment