序列化问题“scala.math.BigDecimal 没有无参数默认构造函数”
我是 scala 编程和 java 新手,所以这是我的问题:
我有一个要使用 BigDecimal 属性序列化的对象
import java.util.Date
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter
import reflect.BeanProperty
class TestObject {
@XmlJavaTypeAdapter(classOf[BigDecimalAdapter])
var test: BigDecimal = 0.00
}
我收到此错误:
scala.math.BigDecimal does not have a no-arg default constructor
XmlAdapter:
import javax.xml.bind.annotation.adapters.XmlAdapter
class BigDecimalAdapter extends XmlAdapter[String, BigDecimal] {
def unmarshal(str: String) = BigDecimal(str)
def marshal(bD: BigDecimal) = bD.toString()
}
SOAPServer:
import javax.jws.soap.SOAPBinding
import javax.jws.{WebParam, WebMethod, WebService}
import javax.xml.ws.Endpoint
@WebService(targetNamespace="test", name="testws", portName="test", serviceName="wsTest")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
class Server {
@WebMethod(action = "test")
def test(@WebParam(name = "testParam") testParam:TestObject): TestObject = {
return testParam
}
}
object SoapServer { // defined Companion Object for our class
def main(args: Array[String]) { // main method to make this a runnable application
val endpoint = Endpoint.publish("http://192.168.189.132:8080/wsTest", new Server())
System.out.println("Binded to port 8080. Waiting for requests...")
}
}
I'm new to scala programming and java so here is my problem:
I have an object to be serialized with a BigDecimal Property
import java.util.Date
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter
import reflect.BeanProperty
class TestObject {
@XmlJavaTypeAdapter(classOf[BigDecimalAdapter])
var test: BigDecimal = 0.00
}
I receive this error:
scala.math.BigDecimal does not have a no-arg default constructor
XmlAdapter:
import javax.xml.bind.annotation.adapters.XmlAdapter
class BigDecimalAdapter extends XmlAdapter[String, BigDecimal] {
def unmarshal(str: String) = BigDecimal(str)
def marshal(bD: BigDecimal) = bD.toString()
}
SOAPServer:
import javax.jws.soap.SOAPBinding
import javax.jws.{WebParam, WebMethod, WebService}
import javax.xml.ws.Endpoint
@WebService(targetNamespace="test", name="testws", portName="test", serviceName="wsTest")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
class Server {
@WebMethod(action = "test")
def test(@WebParam(name = "testParam") testParam:TestObject): TestObject = {
return testParam
}
}
object SoapServer { // defined Companion Object for our class
def main(args: Array[String]) { // main method to make this a runnable application
val endpoint = Endpoint.publish("http://192.168.189.132:8080/wsTest", new Server())
System.out.println("Binded to port 8080. Waiting for requests...")
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可能希望使用 java.math.BigDecimal,而不是 scala.math.BigDecimal。使用完全限定路径名:
jaxb 框架似乎需要一个无参数构造函数;我对它不太熟悉,无法理解为什么
I think you probably want to be using
java.math.BigDecimal
, as opposed toscala.math.BigDecimal
. Use the fully-qualified path name:It seems like the jaxb framework is expecting a no-arg constructor; I'm not familiar enogh with it to understand why