开发者

How to convert from hibernate SQLQuery result to JSON

开发者 https://www.devze.com 2023-04-12 07:32 出处:网络
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\");

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

精彩评论

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