can't not cast to java.util.map
See original GitHub issuethe heml is like this:
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html>
<head>
<title>tmpl1</title>
</head>
<body>
<div th:each="item : ${rows}">
<h1 th:text="${item.title}"></h1>
</div>
</body>
</html>
and the controller is like this:
@RequestMapping(value="tmpl1")
public ModelAndView testTmpl1(){
List<Integer> ids = new ArrayList<Integer>();
ids.add(100052);
ids.add(100052);
ids.add(100052);
ids.add(100052);
ids.add(100052);
List<Item> itemsByIds = itemService.getItemsByIds(ids);
ModelAndView modelAndView = new ModelAndView("test/tmpl1");
modelAndView.addObject("rows",itemsByIds);
return modelAndView;
}
@RequestMapping(value="tmpl2")
public ModelAndView testTmpl2(){
List<Integer> ids = new ArrayList<Integer>();
ids.add(100052);
ids.add(100052);
ids.add(100052);
ids.add(100052);
ids.add(100052);
List<Item> itemsByIds = itemService.getItemsByIds(ids);
ModelAndView modelAndView = new ModelAndView("test/tmpl1");
modelAndView.addObject("rows",JSON.toJSON(itemsByIds));
return modelAndView;
}
!!!when i visited tmpl2 , and then i go to visit tmpl1, it will throw a exception , can’t not cast to java.util.map ,
the JSON library is fastjson
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<!-- <version>1.1.35</version> -->
<version>1.1.46</version>
</dependency>
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
java.lang.String cannot be cast to java.util.Map - Stack Overflow
String cannot be cast to java.util.Map" . The error only appears after the code is run, not while compiling, nor in NetBeans IDE....
Read more >How to fix java.lang.classcastexception cannot be cast to in Java
As name suggests ClassCastException in Java comes when we try to type cast an object and object is not of the type we...
Read more >Jackson: java.util.LinkedHashMap cannot be cast to X
Sometimes, we may encounter java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to X when we try to deserialize JSON or XML ...
Read more >Error "java.lang.String cannot be cast to java.util.Map" When ...
Error "java.lang.String cannot be cast to java.util.Map" When Uploading a Server Side Extension (SSE) (Doc ID 2418722.1).
Read more >[Fixed] java.util.HashMap$Values cannot be cast to class java ...
HashMap values returns java.util.Collection and you can not cast Collection to List or ArrayList. It will throw ClassCastException in this scenario.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, testTmpl1() should work with th:text=“${item.title}” because the Item class has a getTitle() method.
Try to use th:text=“${item[‘title’]}” (SPel notation for Maps) for testTmpl2() as you don’t have a getTitle() method.
Thanks. That solved the problem.