2013-04-26 125 views
0

我使用的是默認的傑克遜映射器,像這樣的球衣錯誤轉換:2維數組

@POST 
@Consumes(MediaType.APPLICATION_JSON) 
@Produces(MediaType.TEXT_PLAIN) 
public String classify(@HeaderParam("training") boolean training, SamplePacket sp) { 
... 
} 

其中樣本包看起來是這樣的:

@XmlRootElement 
public class SamplePacket { 
private String id; 
    private int[][] matrix; 
    private int width; 
    private int height; 
    private String label; 
    private int originalMatrixSize; 

我交的數據是這樣的:

{"id":"web-1366985890725","matrix":[[161,195,90,197,126,168,126,212], 
... 
[169,199,101,200,135,177,135,217]],"width":320,"height":240,"originalMatrixSize":26} 

問題是,當我停在一個破發點後內(分類)方法sp我得到的對象包含除正常大小的所有第二維數組長度均爲零的矩陣之外的所有正確字段。

我該怎麼辦?最好不實現自定義映射

+0

你可以嘗試genson庫,你的矩陣情況下應該工作在箱子外面。 – eugen 2013-04-28 19:44:13

回答

0

顯然默認解析器預計這句法:

{"height":"480","id":"No31 18:29:10 24/02/2013","label":"No","matrix": 
[ 
{"item":["349","388","279","387","315","377","314","389"]} 
["349","389","279","388","315","377","314","392"]},{"item":["349","388","279","387","315","377","314","390"]},{"item":["348","386","279","387","314","376","313","389"]},{"item":["348","387","278","386","314","376","314","389"]}],"originalMatrixSize":"32","width":"640"} 
+1

那麼你很可能不使用傑克遜映射器 - 你的原始數據格式應該可以正常工作。而是你正在使用其他公約。爲了測試這個,你可以在澤西島以外創建'ObjectMapper'並驗證獨立行爲;如果這是真的,找出你爲什麼不使用Jackson POJO映射。 – StaxMan 2013-04-27 16:33:17