java.sql.Timestamp does not have a no-arg default constructor.

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions

java.sql.Timestamp does not have a no-arg default constructor.

this problem is related to the following location:

at java.sql.Timestamp

at public java.sql.Timestamp com.yazuo.api.service.account.vo.MerchantProductVo.getBeginTime()

at com.yazuo.api.service.account.vo.MerchantProductVo

使用cxf 框架 构造webservice 接口的使用, 如果返回对象中定义了 java.sql.Timestamp 会出现以上异常,   原因 , cxf 解析返回对象的时候需要使用无参构造函数, java中本来默认每一个类都有一个无参构造函数, 但是我们发现



 

有这连个构造函数后, java 的默认无参构造函数实效, 到时cxf 无法解析到这个类,出现以上错误

 

 

解决办法:

 

1、 在接口中不使用  java.sql.Timestamp

2、使用XmlAdapter 来覆盖绕过

 

 

其中2的使用方式:

 

import java.sql.Timestamp;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter; 
public class TimestampAdapter extends XmlAdapter<Date, Timestamp> {  
  
    public Date marshal(Timestamp v) {  
        return new Date(v.getTime());  
    }  
  
    public Timestamp unmarshal(Date v) {  
        return new Timestamp(  
            v.getTime());  
    }  
}

 

	}

	@XmlJavaTypeAdapter(value = TimestampAdapter.class, type = Timestamp.class)
	public java.sql.Timestamp getBeginTime() {
		return beginTime;
	}

	public void setBeginTime(java.sql.Timestamp beginTime) {
		this.beginTime = beginTime;
	}

	@XmlJavaTypeAdapter(value = TimestampAdapter.class, type = Timestamp.class)
	public java.sql.Timestamp getEndTime() {
		return endTime;
	}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值