0

Alright guys, I'm just trying to get a list of objects from my table 'ItemList'. I feel like I'm just messing up the query that I'm using. This is the code I'm running:

    public List<GetListsDTO> getAllLists() {
        Query query = currentSession.createQuery("SELECT L.name, L.listType, L.position FROM ItemList L ORDER BY L.position ASC");

        try{
            System.out.println(query.list());
            return (List<GetListsDTO>) query.list();
        }
        catch(Exception e){
            e.printStackTrace();
            return null;
        }
    }

And this is the result on Postman:

[
    [
        "list1",
        "Clothing",
        1
    ],
    [
        "list2",
        "Clothing",
        2
    ]
]

As you can see it retrieves the right information, but I can't figure out how to cast this into an actual object instead of having it as arrays of strings.

Help would be appreciated :)

EDIT: This is the result I'm looking for:

[
    {
        "name": "list1",
        "listType": "Clothing",
        "position": 1
    },
    {
        "name": "list2",
        "listType": "Clothing",
        "position": 2
    }
]

3
  • they are all objects, you should be more specific, also mysql and other rdms can output json as well, that is a possiblity Commented Feb 29, 2020 at 13:44
  • I'm not sure if you get notified by my edit, I made the preferred situation more specific. Maybe you could help me out. @nbk Commented Feb 29, 2020 at 14:10
  • 1
    as i said directly in mysql stackoverflow.com/questions/60379551/… or in java stackoverflow.com/questions/21576645/… there various possibilitys search please there many solutions for it Commented Feb 29, 2020 at 14:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.