다음과 같이 자신 만의 CustomSerializer를 작성할 수 있습니다.
public class ByteArraySerializer extends JsonSerializer<byte[]> {
@Override
public void serialize(byte[] bytes, JsonGenerator jgen,
SerializerProvider provider) throws IOException,
JsonProcessingException {
jgen.writeStartArray();
for (byte b : bytes) {
jgen.writeNumber(unsignedToBytes(b));
}
jgen.writeEndArray();
}
private static int unsignedToBytes(byte b) {
return b & 0xFF;
}
}
이 코드는 Base64 문자열 대신 부호없는 바이트 배열 표현을 반환합니다.
{
"mimetype": "text/plain",
"value": [
81,
109,
70,
122,
90,
83,
65,
50,
78,
67,
66,
84,
100,
72,
74,
108,
89,
87,
48,
61
]
}
PS : 당신의 POJO와 함께 사용하는 방법
: 그것은 출력의의 여기
public class YourPojo {
@JsonProperty("mimetype")
private String mimetype;
@JsonProperty("value")
private byte[] value;
public String getMimetype() { return this.mimetype; }
public void setMimetype(String mimetype) { this.mimetype = mimetype; }
@JsonSerialize(using= com.example.yourapp.ByteArraySerializer.class)
public byte[] getValue() { return this.value; }
public void setValue(String value) { this.value = value; }
}
그리고는 예입니다이 시리얼 라이저는 I에 유래에서 발견 된 일부 답변의 혼합이다 .
그러나 Base64에는 다양한 종류가 있음을 유의하십시오. –