0
我試圖序列化/反序列化一堆集合,並且在閱讀Set<E>
時遇到問題。 我創建了一個新的類:CollectionTypesSerializer來序列化/反序列化我的所有集合,但它不起作用。 這裏是我的代碼示例:如何使用PofSerializer讀取集合
public class CollectionTypesPofSerializer implements PofSerializer {
private static final int ID = 0;
// Set
private static final int SET1NUMBER = 1; //Set<Number>
private static final int SET2MAPBASICTYPESCOLLECTION = 2; //Set<Map<BasicTypesCollection>>
private static final int SET3INNERTYPESPRIMITIVEINNERTYPES = 3; //Set<InnerTypes.PrimitiveInnerTypes>
@Override
public Object deserialize(PofReader reader) throws IOException {
CollectionTypes collection = new CollectionTypes();
collection.id = reader.readInt(ID);
collection.set1 = (Set<Number>) reader.readCollection(SET1NUMBER, null);
collection.set2 = (Set<Map<BasicTypes, Collection<?>>>) reader.readCollection(SET2MAPBASICTYPESCOLLECTION, null);
collection.set3 = (Set<InnerTypes.PrimitiveInnerTypes>) reader.readCollection(SET3INNERTYPESPRIMITIVEINNERTYPES, null);
reader.readRemainder();
return collection;
}
我有很多在這個方法中其他類別的,他們不有同樣的問題。 我知道問題是什麼,我不能使用reader.readCollection(...)
與設置和演員是不夠的。但是,我不知道有任何其他的方式來做到這一點。你能幫我麼?
謝謝。