那不是有效的JSON。将
"profilePhoto"
要发送的字母数字。这不是有效的类型。它可以是数字或字符串。如果它是字符串,则将其用"
引号引起来。将其设为有效字符串后,解串器将不知道如何将字符串映射到
byte[]
。您将需要创建一个自定义(反)序列化器。使用MOXy,您可以使用XmlAdapter
。一个例子会像import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.util.base64;
public class base64ByteArrayAdapter extends XmlAdapter
{ @Overridepublic byte[] unmarshal(String base64) throws Exception { return base64.getDeprer().depre(base64);}@Overridepublic String marshal(byte[] bytes) throws Exception { return base64.getEnprer().enpreToString(bytes);}}
该
unmarshal会处理传入的base64字符串转换为一个
byte[],并且
marshal将处理的转换
byte[]到以base64字符串。
然后,您只需要使用适配器在Bean中注释属性即可
@XmlJavaTypeAdapter(base64ByteArrayAdapter.class)public byte[] getProfilePhoto() {}


