Corda节点驱动程序无法获取自定义序列化程序
我正在编写一个cordapp,其中我需要使用需要自定义序列化程序的状态类。我已经根据定义了一个,但是当我试图通过corda节点驱动程序(完全按照corda helloworld模板)运行契约测试时,它似乎没有被选中 下面是类定义(经过适当的模糊处理):Corda节点驱动程序无法获取自定义序列化程序,corda,Corda,我正在编写一个cordapp,其中我需要使用需要自定义序列化程序的状态类。我已经根据定义了一个,但是当我试图通过corda节点驱动程序(完全按照corda helloworld模板)运行契约测试时,它似乎没有被选中 下面是类定义(经过适当的模糊处理): 公共类BlahBlahsSerializer实现SerializationCustomSerializer{ 公共代理(BlahBlahProxy代理){ /*恳求*/ } 公共BlahBlahProxy toProxy(BlahBlah州){
公共类BlahBlahsSerializer实现SerializationCustomSerializer{
公共代理(BlahBlahProxy代理){
/*恳求*/
}
公共BlahBlahProxy toProxy(BlahBlah州){
/*恳求*/
}
}
}
上面的.class文件位于驱动程序创建的cordap jar中,BlahBlahProxy.class、contract和state类也是如此。所有这些类都与state和contract类本身在同一个包中
我已经为corda启用了调试日志记录,我可以看到很多类似这样的行
[测试工作者]CachingCustomSerializerRegistry-action=“使用自定义序列化程序”,class=java.security.PublicKey,declaredType=java.security.PublicKey
但是我们班没有排队
我想知道我是否还需要做些什么来启用自定义序列化程序?我认为@fowler相对正确,这在过去可能是一个问题 看看Corda(4.5)的最新版本,看看是否可以在那里使用自定义序列化程序。希望您不会遇到这样的问题:
/**
* The class lacks a public constructor that takes parameters it can associate
* with its properties and is thus not serializable by the CORDA serialization
* framework.
*/
class Example {
private int a;
private int b;
public int getA() { return a; }
public int getB() { return b; }
public Example(List<int> l) {
this.a = l.get(0);
this.b = l.get(1);
}
}
/**
* This is the class that will Proxy instances of Example within the serializer
*/
public class ExampleProxy {
/**
* These properties will be serialized into the byte stream, this is where we choose how to
* represent instances of the object we're proxying. In this example, which is somewhat
* contrived, this choice is obvious. In your own classes / 3rd party libraries, however, this
* may require more thought.
*/
private int proxiedA;
private int proxiedB;
/**
* The proxy class itself must be serializable by the framework, it must thus have a constructor that
* can be mapped to the properties of the class via getter methods.
*/
public int getProxiedA() { return proxiedA; }
public int getProxiedB() { return proxiedB; }
public ExampleProxy(int proxiedA, int proxiedB) {
this.proxiedA = proxiedA;
this.proxiedB = proxiedB;
}
}
/**
* Finally this is the custom serializer that will automatically loaded into the serialization
* framework when the CorDapp Jar is scanned at runtime.
*/
public class ExampleSerializer implements SerializationCustomSerializer<Example, ExampleProxy> {
/**
* Given an instance of the Example class, create an instance of the proxying object ExampleProxy.
*
* Essentially convert Example -> ExampleProxy
*/
public ExampleProxy toProxy(Example obj) {
return new ExampleProxy(obj.getA(), obj.getB());
}
/**
* Conversely, given an instance of the proxy object, revert that back to an instance of the
* type being proxied.
*
* Essentially convert ExampleProxy -> Example
*/
public Example fromProxy(ExampleProxy proxy) {
List<int> l = new ArrayList<int>(2);
l.add(proxy.getProxiedA());
l.add(proxy.getProxiedB());
return new Example(l);
}
}
/**
*该类缺少一个公共构造函数,该构造函数接受它可以关联的参数
*具有其属性,因此不能通过CORDA序列化进行序列化
*框架。
*/
课例{
私人INTA;
私人INTB;
public int getA(){return a;}
public int getB(){return b;}
公共示例(列表l){
这个.a=l.get(0);
这个.b=l.get(1);
}
}
/**
*这是将在序列化程序中代理示例实例的类
*/
公共类ExampleProxy{
/**
*这些属性将被序列化到字节流中,这是我们选择如何
*表示我们代理的对象的实例
*这种选择很明显是人为的。但是,在您自己的类/第三方库中
*可能需要更多的思考。
*/
私人代理;
私有int代理B;
/**
*代理类本身必须可以被框架序列化,因此它必须有一个
*可以通过getter方法映射到类的属性。
*/
public int getProxiedA(){return proxiedA;}
public int getProxiedB(){return proxiedB;}
公共示例代理(int-proxiedA,int-proxiedB){
this.proxiedA=proxiedA;
this.proxiedB=proxiedB;
}
}
/**
*最后,这是将自动加载到序列化中的自定义序列化程序
*运行时扫描CorDapp Jar时的框架。
*/
公共类ExampleSerializer实现SerializationCustomSerializer{
/**
*给定Example类的实例,创建代理对象ExampleProxy的实例。
*
*本质上转换示例->示例代理
*/
公共示例Proxy toProxy(示例obj){
返回新的ExampleProxy(obj.getA(),obj.getB());
}
/**
*相反,给定代理对象的实例,将其恢复为代理对象的实例
*正在代理的类型。
*
*本质上转换ExampleProxy->Example
*/
proxy的公共示例(ExampleProxy代理){
列表l=新阵列列表(2);
l、 添加(proxy.getProxiedA());
l、 添加(proxy.getProxiedB());
返回新示例(l);
}
}
来源于文档:您使用的是哪一版本的Corda?操作系统4.3?我这样问是因为我们解决了
classgraph
不总是加载URL附件的问题(在无法正确扫描URL附件的地方出现了问题)。为了修复这个问题,我们在OS4.4(和企业版)中将classgraph
更新为4.8.58。是的,它是OS4.3。我会在4.4中检查它是否有效,谢谢你提供的信息@igor I也有类似的问题,看看代码,似乎测试总是在忽略cordapps中定义的自定义序列化程序的序列化环境中运行。你找到解决办法了吗?@Ulrikrasumssen我没有,只是暂时设法解决了这个问题。但这正是我所经历的。等待OS4.4发布再发布再尝试是的,这似乎确实是OS4.3特有的一个bug
/**
* The class lacks a public constructor that takes parameters it can associate
* with its properties and is thus not serializable by the CORDA serialization
* framework.
*/
class Example {
private int a;
private int b;
public int getA() { return a; }
public int getB() { return b; }
public Example(List<int> l) {
this.a = l.get(0);
this.b = l.get(1);
}
}
/**
* This is the class that will Proxy instances of Example within the serializer
*/
public class ExampleProxy {
/**
* These properties will be serialized into the byte stream, this is where we choose how to
* represent instances of the object we're proxying. In this example, which is somewhat
* contrived, this choice is obvious. In your own classes / 3rd party libraries, however, this
* may require more thought.
*/
private int proxiedA;
private int proxiedB;
/**
* The proxy class itself must be serializable by the framework, it must thus have a constructor that
* can be mapped to the properties of the class via getter methods.
*/
public int getProxiedA() { return proxiedA; }
public int getProxiedB() { return proxiedB; }
public ExampleProxy(int proxiedA, int proxiedB) {
this.proxiedA = proxiedA;
this.proxiedB = proxiedB;
}
}
/**
* Finally this is the custom serializer that will automatically loaded into the serialization
* framework when the CorDapp Jar is scanned at runtime.
*/
public class ExampleSerializer implements SerializationCustomSerializer<Example, ExampleProxy> {
/**
* Given an instance of the Example class, create an instance of the proxying object ExampleProxy.
*
* Essentially convert Example -> ExampleProxy
*/
public ExampleProxy toProxy(Example obj) {
return new ExampleProxy(obj.getA(), obj.getB());
}
/**
* Conversely, given an instance of the proxy object, revert that back to an instance of the
* type being proxied.
*
* Essentially convert ExampleProxy -> Example
*/
public Example fromProxy(ExampleProxy proxy) {
List<int> l = new ArrayList<int>(2);
l.add(proxy.getProxiedA());
l.add(proxy.getProxiedB());
return new Example(l);
}
}