当我想将ResultScanner对象写入磁盘时,我遇到了这个错误:
Exception in thread "main" java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.hadoop.hbase.client.ClientScanner
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at cache1.CacheManager.getCache(CacheManager.java:112)
at cache1.Cache1.main(Cache1.java:43)
Caused by: java.io.NotSerializableException: org.apache.hadoop.hbase.client.ClientScanner
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at cache1.CacheManager.putCache(CacheManager.java:102)
at cache1.Cache1.main(Cache1.java:41)
据我所知,问题在于ResultScanner(ClientScanner)无法序列化。由于我无法访问此类,如何修复此序列化问题?或者有没有其他方法将此对象存储到文件中?
答案 0 :(得分:0)
不幸的是,您需要自己执行序列化,因为具有Serializable接口JVM无法为您执行此操作。
扩展此类时,您可以实现readObject和writeObject,并通过自己存储所有状态来序列化它(您还可以阅读:How to serialize a non-serializable in Java?)。
我希望有所帮助。