how to convert LinkedHashMap to Custom java object?

前端 未结 3 1194
孤独总比滥情好
孤独总比滥情好 2020-12-29 21:49

I\'m trying to get the data from one app to another via RESTful WS and it works, but I cannot use this data since I cannot cast it... WS returns a List of objects like this:

3条回答
  •  -上瘾入骨i
    2020-12-29 22:11

    You need to do this:

    List myObjects =
        mapper.readValue(jsonInput, new TypeReference>(){});
    

    (From this SO answer)

    The reason you have to use TypeReference is because of an unfortunate quirk of Java. If Java had a proper generics, I bet your syntax would have worked.

提交回复
热议问题