【发布时间】:2015-01-15 20:17:51
【问题描述】:
我正在做上传图像的项目,为此我将图像转换为 base64 字符串,现在在我的 DTO 中,我已将字节数组反序列化如下:
class DecodePhoto extends JsonDeserializer<byte[]> {
@Override
public byte[] deserialize(JsonParser jsonparser, DeserializationContext arg1)
throws IOException, JsonProcessingException {
String data = jsonparser.getText();
try {
byte[] decodedBytes = org.apache.commons.codec.binary.Base64.decodeBase64(data);
return decodedBytes;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
在图像中调用 ajax 后,出现以下错误:
java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.decodeBase64(Ljava/lang/String;)
这里有什么问题?我附上了 jar common-codec-1.9.jar 和 jackson-databind-2.3.2.jar
但在调试模式下(类文件编辑器)显示如下
JAR 文件 jackson-databind-2.3.2.jar 没有源附件。
请帮我反序列化字节数组?
【问题讨论】:
-
this 可以帮到你
标签: spring bytearray deserialization image-uploading json-deserialization