2016-10-03 34 views
0

我的要求是獲取所有選定的列並以Json字符串形式保存到數據庫中,並且再次必須將這些列轉換回對象列表並返回到UI,我的Json看起來像這樣,我想要維度列表,我怎麼能做到這一點?請給我建議。如何從使用映射器的具有多個引用單元的JSON字符串獲取對象列表?

{ 
    "dimensions": [{ 
     "displayName": "Advertised Products", 
     "name": "Product", 
     "selectable": false, 
     "multipleSelect": true, 
     "hasFavorites": true, 
     "showCancel": false, 
     "showClear": false, 
     "hasCustomObjects": true, 
     "isPrimary": true, 
     "searchable": true, 
     "editable": true 
    }, { 
     "displayName": "Companion Products", 
     "name": "Product", 
     "selectable": false, 
     "multipleSelect": true, 
     "hasFavorites": true, 
     "showCancel": false, 
     "showClear": false, 
     "hasCustomObjects": true, 
     "isPrimary": true, 
     "searchable": true, 
     "editable": true 
    }, { 
     "displayName": "Fsp Products", 
     "name": "Product", 
     "selectable": false, 
     "multipleSelect": true, 
     "hasFavorites": true, 
     "showCancel": false, 
     "showClear": false, 
     "hasCustomObjects": true, 
     "isPrimary": true, 
     "searchable": true, 
     "editable": true 
    }] 
} 
+0

你不知道如何將數據保存到數據庫嗎? – xFighter

回答

0

創建一個具有Dimension對象引用,setters和getters的DimensionTO pojo。

public class DimensionTO { 
    private Dimension dimension; 

    public Dimension getDimension() { 
     return dimension; 
    } 

    public void setUser(Dimension dimension) { 
     this.dimension= dimension; 
    } 

} 

使用對象映射器讀取維度列表,

final ObjectMapper mapper = new ObjectMapper(); 
WatcherTO[] dimensionList = mapper.readValue(passYourJson, WatcherTO[].class); 

現在我們可以迭代dimensionList得到每個維度對象。

相關問題