二维数组的错误转换

时间:2013-04-26 14:38:51

标签: json jersey jackson

我正在使用带有默认杰克逊映射器的球衣,如下所示:

@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}

问题是当我停在post(classify)方法内的断点时,我得到的sp对象包括所有正确的字段,除了矩阵的主数组大小正确但所有第二维数组的长度为零。

我该怎么办?最好不要实现自定义映射器

1 个答案:

答案 0 :(得分: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"}