Doubt when generating REST of return of Procedure in jersey

Asked

Viewed 174 times

0

I have a method where his return is a list, based on an execution of a trial in the bank

 StoredProcedureQuery spq
                = em.createStoredProcedureQuery("PROCEDURE");
 ....

The return of this query are some fields of a table, and others are calculated fields. And this return I make available in json

@GET
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
....

Well, I have a small problem, the json generated from this trial is invalid, the jersey puts keys in front and at the end, and does not name the fields, only the values, return example:

   ["300", "ABCD", "Teste"]

In other calls I convert the return of the process into object

StoredProcedureQuery spq
                = em.createStoredProcedureQuery("PROCEDURE", MinhaClasse.class);

and it works, but this time, the returns are not from fields in the database, but some calculated fields, so I can’t do that.

Does anyone know what can be done in my case?

Example of Return Procedure:

-Product Name and Code - OK, I have in the entity -Total Value of the items in stock, This field is calculated in the Precedent, I cannot add in the Entity. Among other calculated fields it returns.

  • How is this Procedure return? A string list or an object with the filled attributes?

  • The return of the method is a List, in the Procedure query it seems to me to be a Hashmap that Storedprocedurequery returns, it has the name of the fields and the values, but in the JSON conversion, jersey "ignores" the fields and plays only the values.

  • I believe that the converter is not interpreting the return correctly (it is interpreting as if it were a list and not as a Hashmap). So, to be sure, try to take the values that are returned in the past and mount an object (or list of objects, depending on the situation) and try to see if it converts the values correctly with the field names.

  • Actually I was mistaken, the problem is that the return of the Storedprocedurequery already comes without the name of the fields, only a list with the return values of the past. any idea what I can do in this case?

  • I thought about creating a return class, but I have fields that are not from the table, and the method requires it to be a @Entity, otherwise it throws an Entity exception not found.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.