java class 的隐式 jsonFormat
Implicit jsonFormat for java class
我有一个生成的 java class:
package cc.notsoclever.customerservice
public class Customer {
protected String name;
public String getName() {
return name;
}
public void setName(String value) {
this.name = value;
}
}
(由WSDL生成,提供SOAP接口,不过没关系)
我想连接到 JSON 接口,所以我需要一个隐式 jsonFormat - 我已经尝试过:
package cc.notsoclever.customerservice
object CustomerProtocol {
import spray.json._, spray.json.DefaultJsonProtocol._
object Customer {
implicit val format = jsonFormat(Customer.apply, "name")
}
}
但是导致错误:
...value apply is not a member of object cc.notsoclever.customerservice.CustomerProtocol.Customer
[error] Note: implicit value format is not applicable here because it comes after the application point and it lacks an explicit result type
[error] implicit val format = jsonFormat(Customer.apply, "name")
[error] ^
是否可以定义将使用 public getter 和 setter 的隐式格式?还是我需要手动定义编组?
Spray 的 jsonFormatX 助手适用于案例 类。您可以编写手动格式或使用像 Jackson 这样面向 Java Beans 的库。
我有一个生成的 java class:
package cc.notsoclever.customerservice
public class Customer {
protected String name;
public String getName() {
return name;
}
public void setName(String value) {
this.name = value;
}
}
(由WSDL生成,提供SOAP接口,不过没关系)
我想连接到 JSON 接口,所以我需要一个隐式 jsonFormat - 我已经尝试过:
package cc.notsoclever.customerservice
object CustomerProtocol {
import spray.json._, spray.json.DefaultJsonProtocol._
object Customer {
implicit val format = jsonFormat(Customer.apply, "name")
}
}
但是导致错误:
...value apply is not a member of object cc.notsoclever.customerservice.CustomerProtocol.Customer
[error] Note: implicit value format is not applicable here because it comes after the application point and it lacks an explicit result type
[error] implicit val format = jsonFormat(Customer.apply, "name")
[error] ^
是否可以定义将使用 public getter 和 setter 的隐式格式?还是我需要手动定义编组?
Spray 的 jsonFormatX 助手适用于案例 类。您可以编写手动格式或使用像 Jackson 这样面向 Java Beans 的库。