我是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...")
}
}
答案 0 :(得分:3)
我认为您可能希望使用java.math.BigDecimal
,而不是scala.math.BigDecimal
。使用完全限定的路径名称:
import java.math.{BigDecimal => JDec}
var test: JDec = new JDec(0)
似乎jaxb框架期待一个无参数的构造函数;我不熟悉它以理解为什么