serializable

StreamCorruptedException when sending Serialized objects via Bluetooth

我怕爱的太早我们不能终老 提交于 2019-12-04 12:59:37
I have a Serialized class that I need to send as an object via Bluetooth, and also implements Runnable. As such, I set a few variables first, then send it as an object to be executed by another Android device, which will then set its result into a variable, and send back the same object with the result in one of the variables. I have been using the following two methods to serialize my object and get a ByteArray before sending them through the OutputStream of my BluetoothSocket, and to deserialize that ByteArray to get back my object. public static byte[] serializeObject(Object o) throws

ArrayList cannot be cast to custom class extending ArrayList

两盒软妹~` 提交于 2019-12-04 09:06:43
I have class mentioned below: public class JsonHistoryList extends ArrayList<JsonHistory> implements Serializable{} I wish to pass it through intent using timerService.putExtra(TimerService.ACTIVITY_LIST_ARG, activities); But after I receive it (way below) JsonHistoryList temp = (JsonHistoryList) intent.getSerializableExtra(TimerService.ACTIVITY_LIST_ARG); in my service it gives me exception: Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.epstim.captime.jsonmodel.JsonHistoryList I don't understand why java can't handle that operation. I've changed my code in

Java序列化之Serializable

萝らか妹 提交于 2019-12-04 08:05:17
1.需求 1.什么是Java序列化 2.详解 1.序列化 理解为"打碎"即可 2.在书本上序列化的意思是将Java对象转为二进制 3.java平台允许我们在内存中创建对象,当JVM运行时对象才能存在,如果JVM停止,对象消失 如果我们需要Java对象在JVM停止后,能够保存对象,并且在将来能读取保存的对象,这是需要序列化 3.使用Java序列化 使用Java对象序列化时,会将对象保存为一组字节,对象序列化保存的时对象状态,就是对象的成员变量 对象序列化不会关注类中的静态变量 4.举个栗子 创建一个User类,用于序列化及反序列化 public class User implements Serializable { private static final long serialVersionUID = -6849794470754667710L; private String name; private Integer age; private transient String gender; public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public

Java IO 对象序列化

和自甴很熟 提交于 2019-12-04 08:04:30
1、对象序列化是什么? 一个对象产生之后实际上是在内存中为其开辟了一个存储空间,方便存储信息。 定义可序列化的类: import java.io.Serializable ; public class Person implements Serializable{ private String name ; // 声明name属性 private int age ; // 声明age属性 public Person(String name,int age){ // 通过构造设置内容 this.name = name ; this.age = age ; } public String toString(){ // 覆写toString()方法 return "姓名:" + this.name + ";年龄:" + this.age ; } } 以后此类的对象,就可以被序列化了。变为二进制byte流。 对象的序列化和反序列化: serialVersionUID import java.io.Serializable ; public class Person implements Serializable{ private static final long serialVersionUID = 1L;/*验证版本的一致性*/ private String name ; //

When Java class is instance of Serializable

蹲街弑〆低调 提交于 2019-12-04 07:12:44
I wonder when Java Class is instance of Serializable. As I know class is serializable only if it implements Serializable interface. I'm trying to use junit to generate entity class (from some kind of template) and check if it is serializable. My generated class (which does NOT implement Serializable) looks like: package test; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import javax.annotation.Generated; import javax.persistence.Id; @Entity @Table( name = MyTestTableDto.TABLE_NAME ) public class MyTestTableDto { public static final String

Serializable attribute in silverlight 4

偶尔善良 提交于 2019-12-04 03:59:34
问题 So do we or do we not have a Serializable attribute in silverlight 4? I have some confusing responses on the internet. When I try to use it in my code, i get a namespace error. These are my includes using System; using System.ComponentModel; using System.Collections.Generic; using System.Runtime.Serialization; I have the assemblies System ,System.Runtime.Serialization added to my project. A follow up question is, if it is not available in Silverlight how do I correctly serialize a singleton?

Android App Updating Without Losing Data

我怕爱的太早我们不能终老 提交于 2019-12-04 03:37:12
问题 I'm new to Android development, so I'm trying to do an app that stores information about a warehouse. However, I'm afraid that if I perform an update, the user data will get lost. Do I have to manage which data should remain unchanged upon updating? Also, I would like to know if it would make any difference to use a serializable class or to use an SQL database if I want to keep the data safe. Thanks a lot :) 回答1: When you update the app, SharedPreferences and SQLite will not lose data. So you

How to stop ProGuard from stripping the Serializable interface from a class

蓝咒 提交于 2019-12-04 02:56:44
Is there an explicit way to stop ProGuard from changing a class from implementing an interface? I have a class that implements java.io.Serializable , let's call it com.my.package.name.Foo . I've found that after running through ProGuard, it no longer implements Serializable . I get null after I cast from Serializable to Foo and false if I check an instance with instanceof Serializable . I've made sure to set ProGuard to ignore this class: -keep class com.my.package.name.Foo I've also tried: -keep class com.my.package.name.Foo { *; } and I've also tried the whole package by doing this: -keep

What's the difference between Serialization and simply store the object on disk?

风格不统一 提交于 2019-12-03 22:19:43
I am confused about this. Since when doing implementation of Serializable class, we need to use classes like FileOutputStream , ObjectOutputStream or something like that. Then why not we just use those classes to do things like output a object to a file and input a object from a file to maintain the status of a object directly? Why should we first implement Serializable and then do the same thing? Understand it like this... Serializable is marker interface which denotes that the object of your class can be converted into byte stream and eventually back into java object if required. Initially

GWT - occasional com.google.gwt.user.client.rpc.SerializationException

痞子三分冷 提交于 2019-12-03 17:57:41
问题 we are haunted by occasional occurences of exceptions such as: com.google.gwt.user.client.rpc.SerializationException: Type 'xxx' was not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' and did not have a custom field serializer.For security purposes, this type will not be serialized.: instance = xxx at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:610) at com.google.gwt.user.client.rpc.impl