我有以下字符串要解析(字符串到对象):
{ "langues" :
[
{"iso":"en", "id":1, "flag":[0,144,255,62,1,152,84,62,1,104,50,63,1,32,90,61,1,172,110,66,1,216,...]}
,
{"iso":"fr", "id":2, "flag":[0,208,0,63,1,208,106,62,1,120,49,63,1,32,90,61,1,60,110,...]}
,
{ etc... }
],
"when" : 133111... // timestamp
}
flag
是png图像的字节数组
以下对象:
public class Langues {
private Long when;
private ArrayList<Langue> langues;
public Long getWhen(){ return when; }
public void setWhen(Long when) { this.when=when; }
...
}
public class Langue {
private int id;
private String iso;
private byte[] flag;
// getters / setters
}
这给我一个错误:
ObjectMapper mapper = new ObjectMapper();
Langues node = mapper.readValue(myString, Langues.class);
JsonParseException
Numeric value (144) out of range of Java byte
也许byte []不是正确的容器,或者我可以在某处设置jackson解析器编码吗?
提前感谢!!
[EDIT]
也许用-128编辑字节数组的每个字段都可以做到但是有点棘手,真正浪费时间......
我通过邮件列表联系了codehaus,我很快就用AnsiString而不是UNICODE或Bytes结束了,并且瞧!
{"langues":[{"iso":"zh","id":7,"flag":"iVBORw0KGgoAAAANSUhEUgAAAIAAAABpCAYAAADy...
使用相同的简单代码
ObjectMapper mapper = new ObjectMapper();
Langues node = mapper.readValue(myString, Langues.class);
答案 0 :(得分:1)
也许用-128编辑字节数组的每个字段都可以做到但是有点棘手,真的浪费时间......
我通过邮件列表联系了codehaus,我很快就用AnsiString而不是UNICODE或Bytes结束了,并且瞧!
{"langues":[{"iso":"zh","id":7,"flag":"iVBORw0KGgoAAAANSUhEUgAAAIAAAABpCAYAAADy...
使用相同的简单代码
ObjectMapper mapper = new ObjectMapper();
Langues node = mapper.readValue(myString, Langues.class);