开发者

How to convert from hibernate SQLQuery result to JSON

I have a problem, I'm trying to convert an SQLQuery object result (from Hibernate) to a JSON.

   SQLQuery q = session.createSQLQuery("SELECT * FROM table");
   List<javaBean> list = q.list();

Afterward I开发者_高级运维 would like to convert that into a pretty JSON that has all the attribute name.

What's a good strategy? thanks


You can use Google-gson: http://code.google.com/p/google-gson/, it's quite good for converting Java beans to json:

https://sites.google.com/site/gson/gson-user-guide#TOC-Object-Examples


You could hook up a JAX-RS service to return your bean as JSON. Take a look at Jersey.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜