所以基本上我在一个Android应用程序上工作,我有一个后端服务器。我向服务器发送一个字节数组,并将其存储在数据库中。我正在使用Spring,所以存储字节数组的Entity是这样的:
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApplicationUser {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String username;
private String password;
private String name;
private String lastName;
private int age;
@Lob
private byte[] imageBytes;
}
服务器接收字节数组时,它将接收并存储以下内容:[-1, -40, -1, .....]
现在,当将其发送回时,我将其放置在UserDto对象中,如下所示:
public class UserDto {
String username;
String password;
String name;
String lastName;
int age;
String location;
Long id;
byte [] imageBytes;
}
UserDto userDto = new UserDto();
userDto.setImageBytes(applicationUser.getImageBytes());
return userDto;
在我的android应用中,我希望它能够返回ImageBytesResponse的调用,如下所示:
public class ImageBytesResponse {
byte[] imageBytes;
public byte[] getImageBytes() {
return imageBytes;
}
public void setImageBytes(byte[] imageBytes) {
this.imageBytes = imageBytes;
}
}
调用方法:Call<ImageBytesResponse> getImageBytes
但是当打电话时,当它返回到android应用程序时,我得到了
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 110 path $.imageBytes
所以从根本上讲,为什么从UserDto-> ImageByteResponse无效? 为什么不能正确地进行反杀菌?我的实体属性是@Lob是一个问题吗?