如果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.