'Tuple to Json (with Java & EntityManager)
For a project, i needed to fetch records from a SQL database into a list of objects (using java for backend). The exchange between the backend and the frontend is made with webservices that use JSON as data encoding.
With simple queries (like a 'list all') it works, as EntityManager.createQuery
uses SELECT *
by default , but for more complex ones it doesn't return anything, even when i checked that the query itself returns the respective entries.
My friend thought of using EntityManager.createNativeQuery
instead of EntityManager.createQuery
to use sql queries without SELECT *
or more complex queries. The problem is, when we get to the backend-frontend exchanges (tested with Postman), it sends tuples instead of JSON. And i'm fairly sure the front-end needs JSON.
I checked what EntityManager.createQuery
and EntityManager.createNativeQuery
return and it seems to be mostly the same. So what is the issue?
Is there a way to turn a tuple into a JSON?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|