Google Gson - deserialize list object? (generic type)

前端 未结 13 2267
灰色年华
灰色年华 2020-11-22 09:42

I want to transfer a list object via Google Gson, but I don\'t know how to deserialize generic types.

What I tried after looking at this (BalusC\'s answer):

13条回答
  •  青春惊慌失措
    2020-11-22 10:10

    In My case @uncaught_exceptions's answer didn't work, I had to use List.class instead of java.lang.reflect.Type:

    String jsonDuplicatedItems = request.getSession().getAttribute("jsonDuplicatedItems").toString();
    List> entries = gson.fromJson(jsonDuplicatedItems, List.class);
    

提交回复
热议问题