2015-09-26 70 views
4

我有一個簡單的用戶類與Double []變量用於指定用戶的位置。FlexJson - 無法序列化雙[]數組

@Document 
public class User { 
    private long id; 
    private Double[] location; 
} 

這是我有試圖序列我的用戶對象

new JSONSerializer() 
      .transform(new ArrayTransformer(), Double[].class) 
      .serialize(object)); 

的代碼,但場上的位置不會得到系列化,其他領域進行序列化,但..可能有人請幫忙嗎?

謝謝!

回答

0

只聲明變量是不夠的,因爲默認情況下它初始化爲null

或者使用setter方法或用和空數組初始化它,例如設定值:

private Double[] location = new Double[10]; 
+0

謝謝阿米拉,我試過添加,但它仍然不會被序列化。我檢查了我的數據庫,確實位置數據在那裏,只是沒有序列化成json ... – user1955934

0

大量嘗試後,我終於設法使其通過明確包括的領域的工作:

final String[] includedFields = {"location"}; 

new JSONSerializer() 
        .include(includedFields) 
        .serialize(object));