byte json 互转_VO对象中byte[]数组JSON转换处理

本文介绍了在VO对象中包含byte[]数组时,如何处理JSON转换的问题。当byte[]转换为String传递给前端,前端再将String转换回byte[]可能会遇到异常。通过自定义序列化和反序列化类`MyByteDeSerializer`和`MyByteSerialize`,可以解决这个问题,确保JSON转换的正确进行。
摘要由CSDN通过智能技术生成

如果VO对象中有byte[]数组如何处理?jason转换的时候,给前端暴露出来的byte[]会转换成String

但是前端发送的请求中,String转换为byte[]可能会抛出异常:

com.fasterxml.jackson.core.JsonParseException: Failed to decode VALUE_STRING as base64 (MIME-NO-LINEFEEDS): Illegal character '"' (code 0x22) in base64 content

at [Source: java.io.PushbackInputStream@1d21ffcf; line: 4, column: 20]

这个时候可以自定义序列化和反序列化方法来处理,具体代码如下:

VO类:OrderVO

import java.util.Date;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import io.swagger.annotations.ApiModel;

import io.swagger.annotations.ApiModelProperty;

import lombok.Data;

/**

*

* OrderVO.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值