对scala 反射不太明了,kryo里涉及到scala内置类时,经常因为没有无参构造而抛异常
Caused by: java.lang.InstantiationException: scala.Some
at java.lang.Class.newInstance0(Class.java:357)
at java.lang.Class.newInstance(Class.java:325)
at com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:676)
... 12 more
思路是,转化成java基础类解决;
obj.asInstanceOf[Option[Any]] 这句简直要了亲命了,一开始在想尽办法想把这个generic的T找到,最后发现Any解决所有问题,对于scala的generic还是需要研究
def writeObjectData(buffer: ByteBuffer, obj: Object): Unit = {
if (obj == None) {
kryo.writeClassAndObject(buffer, None)
} else {
kryo.writeClassAndObject(buffer, obj.asInstanceOf[Option[Any]].get)
}
}
def readObjectData[T](buffer: ByteBuffer, objType: java.lang.Class[T]): T = {
val obj = kryo.readClassAndObject(buffer)
if (obj == None) {
None.asInstanceOf[T]
} else {
Some(obj).asInstanceOf[T]
}
}
分享到:
相关推荐
前端项目-jquery-serialize-object,serialize form fields into an object or JSON
Serialize-javascript 能够序列化 JavaScript 库成含有正则表达式和功能的 JSON 包。示例:var serialize = require('serialize-javascript'); serialize({ str : 'string', num : 0, obj : {foo: ...
sendForm.js-Serialize.js
ajax-axios-url-form-serialize 插件
如果表单域有很多,逐个提取很麻烦,使用这个封装好的可以整体获取,也就是能使用form-serialize库获取整体表单数据。获取的有两种返回值,一种是查询字符串,一种是对象。
JavaWeb新版教程. JSON和Ajax请求&i18n国际化X-jQuery的serialize方法.avi
Serialize.Linq是用于序列化linq表达式的ac#库。 它支持(但不限于)的格式为JSON,XML和BINARY。 安装 通过简单安装: PM> Install-Package Serialize.Linq 建立源 git clone ...
Work with unstructured data and serialize it using Kryo, Protobuf, Avro, and AvroParquet Construct reliable and robust data pipelines and manage data in a data-driven enterprise Implement scalable ...
资源来自pypi官网。 资源全名:monero-serialize-2.0.3.tar.gz
13.form-serialize插件使用.html做一下等级任务
受dominicbarnes / form-serialize的大力启发,但可与npm一起使用,并且本身不包含transform功能。 用法 serialize ( form ) == // {username: 'user1', password: 'my password'} < input name =' username ...
自己写的一个jquery复杂表单序列化工具
How can we implement trees with nodes that have > 2 children?
使用 MFC 串行化数据和 C++ 对象,三个简单的例子程序
原工程地址:https://github.com/viniciussanchez/dataset-serialize 由于使用的了高版本的类信息所以无法在Delphi7中无法使用,这里将其他修改为使用superobject来做JSON部分的处理
form-serialize-and-calculate.html
如果用户仍然想使用它,请设置dubbo.security.serialize.generic.native-java-enable为true环境。 3. 序列化块列表 中引入了嵌入式序列化块列表dubbo-common/src/main/resources/security/serialize.blockedlist。 ...
Serialize() Beyond Active Documents Translating Business Rules What if I'm Not in Big Business, Smart Guy? Automation Prerequisites for Automation Differences from Embedding Implementing ...
Raphael.JSON Raphael.Export Raphael.FreeTransform raphael.serialize
python库,解压后可用。 资源全名:flask_serialize-1.5.2-py2.py3-none-any.whl