警告: Can't transform property 'acceptEvent' from java.lang.String into java.util.List. Will register

警告: Can‘t transform property ‘acceptEvent‘ from java.lang.String into java.util.List. Will register a default Morpher

产生错误的代码:

import net.sf.json.JSONObject;	
public static <T> T jsonToObject(String jsonString, Class<T> pojoCalss) {
		try{
			Object pojo;
			JSONObject jsonObject = JSONObject.fromObject(jsonString);

			pojo = JSONObject.toBean(jsonObject, pojoCalss);
			@SuppressWarnings("unchecked")
			T t = (T)pojo;
			return t;
		}catch(Exception ex){
			return null;
		}
	}

需要实例化的实体类如下:

import java.io.Serializable;
import java.util.List;

/**
 * 传送的消息数据对象
 *
 * @author testcs_dn
 */
public final class Data implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 387186819023110091L;

	// 客户端id
	private String id;
	// 客户端ip
	private String ip;
	// 客户端过期时间
	private int clientTimeOut = 30 * 1000;
	// 服务端过期时间
	private int serverTimeOut = 60 * 1000;
	// 传送数据
	private Object data;
	// 时间戳
	private long timeStamp;
	// 消息类型
	private String operate;
	// 消息返回状态(未处理,已处理(成功、失败))
	private String state;
	// 客户端接收的事件类型
	private List<String> acceptEvent;

	public Data() {
	}

	public String getOperate() {
		return operate;
	}

	public void setOperate(String operate) {
		this.operate = operate;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public long getTimeStamp() {
		return timeStamp;
	}

	public void setTimeStamp(long timeStamp) {
		this.timeStamp = timeStamp;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public int getClientTimeOut() {
		return clientTimeOut;
	}

	public void setClientTimeOut(int clientTimeOut) {
		this.clientTimeOut = clientTimeOut;
	}

	public int getServerTimeOut() {
		return serverTimeOut;
	}

	public void setServerTimeOut(int serverTimeOut) {
		this.serverTimeOut = serverTimeOut;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "Data [id=" + id + ", ip=" + ip + ", clientTimeOut="
				+ clientTimeOut + ", serverTimeOut=" + serverTimeOut
				+ ", data=" + data + ", timeStamp=" + timeStamp + ", operate="
				+ operate + ", state=" + state + ", acceptEvent=" + acceptEvent
				+ "]";
	}

	public List<String> getAcceptEvent() {
		return acceptEvent;
	}

	public void setAcceptEvent(List<String> acceptEvent) {
		this.acceptEvent = acceptEvent;
	}
}

解决方案:

参考:http://www.iteye.com/problems/675

需要使用JSONUtils.getMorpherRegistry().registerMorpher( );注册对应的Morpher,但研究了一番还没搞清楚自定义的Morpher怎么写。

警告: Can't transform property 'acceptEvent' from java.lang.String into java.util.List. Will register

时间: 2024-10-10 18:32:00

警告: Can't transform property 'acceptEvent' from java.lang.String into java.util.List. Will register的相关文章

Attempt to invoke virtual method &#39;boolean java.lang.String.equals(java.lang.Object)&#39; on a null object reference xxx 的问题分析与解决方案

最近,公司要求开发一个APP,所以很苦逼的学习了几天 Android 的上手手册,但是实际运用于开发中还是捉襟见肘,困难重重:好在的是,部门还有几个专门搞安卓的大佬可以问问,哈哈 好了,进入今天的正题吧,前天开发过程中,遇到一个如“标题”所示的问题,百思不得其解!最终上网搜报错的原因,才找到问题的所在:.xml文件中运用到了不存在的标签--我的是因为粗心把<View>写成了<view>,加载的时候找不到该标签,所以页面一直运行不出来. 所以,该问题基本出在于布局页面有错(有的错误页

mybatis之org.apache.ibatis.reflection.ReflectionException: There is no getter for property named &#39;time&#39; in &#39;class java.lang.String&#39;

mybatis接口 List<String> getUsedCate(String time); 配置文件 <select id="getUsedCate" parameterType="java.lang.String" resultType="java.lang.String"> select distinct(cate.cate_name) from account as acc left join conCateg

mybatis部分版本异常invalid comparison: java.util.Date and java.lang.String

严重: Servlet.service() for servlet [spring] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### E

java.lang.String 类的所有方法

java.lang.String 类的所有方法 方法摘要 char charAt(int index) 返回指定索引处的 char 值. int codePointAt(int index) 返回指定索引处的字符(Unicode 代码点). int codePointBefore(int index) 返回指定索引之前的字符(Unicode 代码点). int codePointCount(int beginIndex, int endIndex) 返回此 String 的指定文本范围中的 Un

深入理解java.lang.String

String类是Java编程中应用最广泛的类,所以每一位程序员都应该仔细研究一番String类的内部实现,这样对我们理解String对象的工作机制.避免错误和提升代码效率有很大好处.你若打开Java语言规范 (Java 9),可以看到4.3.3节中对String对象的简述[1]: String对象的实例,表示Unicode码的序列. 一个String对象,有一个恒定不变的值. 字符串字面量是对String实例的引用. 非常量表达式时,“+“操作符连接两个String对象,总是会隐式地产生一个新的

java.lang.String 的 + 号操作到底做了什么事情?

https://www.cnblogs.com/panzi/p/11956782.html 前言  在之前的面试经历中,对于String的考察还是挺频繁的,大致考察以下几个知识点: String 常量池 new String() == 和 equals 的区别 native 方法 String.intern()虽然面试中大体答对了,但是今天早上微信群里的一个问题我却答不上来,这个问题是这样的: String str3 = "what"; String str4 = str3 + &qu

There is no getter for property named &#39;userId&#39; in &#39;class java.lang.String&#39;

[ERROR] 2017-01-18 04:37:06:231 cn.dataenergy.common.CenterHandlerExceptionResolver (CenterHandlerExceptionResolver.java:44) - 统一捕获异常: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Th

org.apache.ibatis.reflection.ReflectionException: There is no getter for property named &#39;parentId&#39; in &#39;class java.lang.String&#39;

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'parentId' in 'class java.lang.String' at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:333) at org.apache.ibatis.reflection.Meta

Mybatis问题:There is no getter for property named &#39;unitId&#39; in &#39;class java.lang.String&#39;

Mybatis遇到的问题 问题: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'unitId' in 'class java.lang.String' at org.mybatis.spring.MyBatisExceptionTransla