序列化问题“scala.math.BigDecimal 没有无参数默认构造函数”

发布于 2024-10-30 01:35:12 字数 1463 浏览 2 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葵雨 2024-11-06 01:35:12

我认为您可能希望使用 java.math.BigDecimal,而不是 scala.math.BigDecimal。使用完全限定路径名:

 import java.math.{BigDecimal => JDec}
 var test: JDec = new JDec(0)

jaxb 框架似乎需要一个无参数构造函数;我对它不太熟悉,无法理解为什么

I think you probably want to be using java.math.BigDecimal, as opposed to scala.math.BigDecimal. Use the fully-qualified path name:

 import java.math.{BigDecimal => JDec}
 var test: JDec = new JDec(0)

It seems like the jaxb framework is expecting a no-arg constructor; I'm not familiar enogh with it to understand why

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文