-6ren">
gpt4 book ai didi

java - 无法写入 JSON 通用对象

转载 作者:行者123 更新时间:2023-12-01 11:44:35 26 4
gpt4 key购买 nike

当我尝试返回通用对象时,出现异常:

@RequestMapping(value="/administration/get_stat_all") 
public @ResponseBody
List<StatAllBean<String>> get_stat_all(..) {

List<StatAllBean<String>> all_stats = new ArrayList<StatAllBean<String>>();
....
return all_stats ;

这是我的对象:

public class StatAllBean<T> {

public Map<T, Long> totalMap ;
public Date date;

异常(exception):

19:14:56.366 [http-nio-8080-exec-9] DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolving exception from handler [<java.lang.reflect.MalformedParameterizedTypeException>]: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: (was java.lang.NullPointerException) (through reference chain: java.util.ArrayList[0]); nested exception is org.codehaus.jackson.map.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: java.util.ArrayList[0])

最佳答案

all_stats 列表是一个空列表,您需要检查:

return ( all_stats.isEmpty() ? null : all_stats );

关于java - 无法写入 JSON 通用对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29264763/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com