Jackson Json指定为不同类型(反序列化和反序列化)

时间:2014-12-22 02:47:41

标签: java json serialization jackson json-deserialization

如何在json处理中将返回字节更改为位图?

private Bitmap imageBitmap;
private byte[] image;

@JsonProperty("image")
public byte[] getImage() {
    return image;
}

public void setImage(byte[] image) {
    this.image = image;
}  

public Bitmap getImageBitmap() {
    return imageBitmap;
}
@JsonProperty("image")
public void setImageBitmap(byte[] imageBitmap) {
    this.imageBitmap = BitmapFactory.decodeByteArray(imageBitmap);
}

1 个答案:

答案 0 :(得分:0)

对未使用的getter和setter使用@JsonIngore

private Bitmap imageBitmap;
private byte[] image;

@JsonProperty("image")
public byte[] getImage() {
    return image;
}

@JsonIgnore
public void setImage(byte[] image) {
    this.image = image;
}  

@JsonIgnore
public Bitmap getImageBitmap() {
    return imageBitmap;
}
@JsonProperty("image")
public void setImageBitmap(byte[] imageBitmap) {
    this.imageBitmap = BitmapFactory.decodeByteArray(imageBitmap);
}