Ich versuche, eine Springboot Usermanagement-Anwendung zu erstellen.Senden von Entity-Objekt in Antwort, die Blob enthält
Ich habe ein Entitätsobjekt, das zwei Blob-Elemente enthält. Hier ist mein Entitätsobjekt.
@Entity
@Table(name="user_meta_profile")
public class UserMetaProfile implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "user_id")
private int user_id;
@Column(name = "resume_file")
@Lob
private Blob resume_file;
@Column(name = "photo")
@Lob
private Blob photo;
@Column(name = "username")
private String username;
public int getUser_id() {
return user_id;
}
public void setUser_id(int user_id) {
this.user_id = user_id;
}
public Blob getResume_file() {
return resume_file;
}
public void setResume_file(Blob resume_file) {
this.resume_file = resume_file;
}
public Blob getPhoto() {
return photo;
}
public void setPhoto(Blob photo) {
this.photo = photo;
}
public void setUsername(String username) {
this.username = username;
}
}
Wie Sie sehen, gibt es zwei ‚resume_file‘ Blob Artikel und ‚Foto‘.
Ich möchte eine JSON-Antwort an den API-Aufruf zurücksenden.
Mein Controller-Code ist wie folgt.
@Controller
@RequestMapping("/v1")
public class UsersController {
@Autowired
private IUserMetaProfileService userMetaProfileService;
@GetMapping("MetaProfile/{id}")
public ResponseEntity<UserMetaProfile> getUserMetaProfileById(@PathVariable("id") Integer id) {
UserMetaProfile userMetaProfile = userMetaProfileService.getUsersById(id);
return new ResponseEntity<UserMetaProfile>(userMetaProfile, HttpStatus.OK);
}
}
Aber wenn ich die API aufrufen, erhalte ich die Ausnahme:
"exception": "org.springframework.http.converter.HttpMessageNotWritableException",
"message": "Could not write JSON document: No serializer found for class java.io.ByteArrayInputStream and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain:
...
...nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.io.ByteArrayInputStream and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
Sie versuchen, einer JSON-Zeichenfolge eine Binärdatei hinzuzufügen. Das ist nicht möglich. Wenn Sie wirklich binäre Dateien zu einem JSON-String hinzufügen möchten, müssen Sie die Binärdateien mit base64 codieren. – Eich