移动端站内信报错 JSON转换失败

bug反馈 未结 1 133
飞行的鱼
飞行的鱼 VIP3 2020-10-22 23:20:24
收藏
产品:vue 版本:7.1
img[/userfiles/fly/441677bc0a064b498b96e72526376e4a/files/1603379822458.] 点进列表时, 会报JSON转换错误 原因是,当发信人被删除时,获取用户名的操作没有判断null 涉及的类有 MailBox.java,MailCompose.java,MailTrash.java 修改后的代码如下 /** * 获取收件人用户Name * * @return */ public String getReceiverNames() { if(StringUtils.isBlank(receiverIds)){ return ""; } List receiverList = Lists.newArrayList(); for (String id : StringUtils.split(receiverIds, ",")) { // 这里没有判断用户为null的情况,会导致Collections3.extractToString()出错 //receiverList.add(SpringContextHolder.getBean(UserService.class).get(id)); User user = SpringContextHolder.getBean(UserService.class).get(id); if (user != null) { receiverList.add(SpringContextHolder.getBean(UserService.class).get(id)); } } return Collections3.extractToString(receiverList, "name", ","); }
回帖
  • 2020-10-27 10:39:07
    建议修改 Collection3.java [pre] @SuppressWarnings("unchecked") public static List extractToList(final Collection collection, final String propertyName) { List list = new ArrayList(collection.size()); try { for (Object obj : collection) { if(obj != null) { list.add(PropertyUtils.getProperty(obj, propertyName)); } } } catch (Exception e) { throw Reflections.convertReflectionExceptionToUnchecked(e); } return list; } [/pre]
    0 回复