[英]How do I return an object in a Java REST API endpoint that has a BLOB property?
在調試模式下,一切正常,直到端點方法的返回語句,當我嘗試通過 Postman 調用它時出現以下錯誤。但是它與返回不包含二進制字段的對象的其他端點一起工作正常。 我錯過了什么嗎?
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 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: org.auxpolice.model.Upload[ “blob”]->com.mysql.cj.jdbc.Blob [“binaryStream”]) 在 com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.8821324:7413) 4.jar:2.13.4] at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1300) ~[jackson-databind-2.13.4.jar:2.13.4] at com.fasterxml.jackson.databind.DatabindContext. reportBadDefinition(DatabindContext.java:400) ~[jackson-databind-2.13.4.jar:2.13.4] 在 com.fasterxml.88156758849 188.databind.ser.impl.unknownserializer.failForement(Unknownerserializer.java:46) .java:29) ~[jackson-databind-2.13.4.jar:2.13.4] at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:728) ~[jackson-databind-2.13.4.jar: 2.13.4] at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:774) ~[jackson-databind-2.13.4.jar:2.13.4] at com.fasterxml.jackson.databind. ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[jackson-databind-2.13.4.jar:2.13.4] at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:728) ~[jackson -databind-2.13.4.8 8202878901088:2.13.4] at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:774) ~[jackson-databind-2.13.4.jar:2.13.4] at com.fasterxml.jackson. databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[jackson-databind-2.13.4.jar:2.13.4] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) ~ [jackson-databind-2.13.4.jar:2.13.4] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319) ~[jackson-databind-2.13.4.jar:2.13.4] at com 。 riter.java:1007) ~[jackson-databind-2.13.4.jar:2.13.4] at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:456) ~[spring-web-5.3.23.jar :5.3.23] at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:104) ~[spring-web-5.3.23.jar:5.3.23] at org.springframework.web.servlet.mvc.method .annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:290) ~[spring-webmvc-5.3.23.jar:5.3.23] at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java: 219) ~[spring-webmvc-5.3.23.jar:5.3.23] 在 org.springframework.web.method.support.HandlerMethodReturnValueHa ndlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:78) ~[spring-web-5.3.23.jar:5.3.23] at org.springframework.hateoas.server.mvc.RepresentationModelProcessorHandlerMethodReturnValueHandler.handleReturnValue(RepresentationModelProcessorHandlerMethodReturnValueHandler.java:108) ~[spring-hateoas -1.5.2.jar:1.5.2] at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:78) ~[spring-web-5.3.23.jar:5.3.23] at org.springframework.web .servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:135) ~[spring-webmvc-5.3.23.jar:5.3.23] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter. invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)~[spring-webmvc-5.3.23.88202878 901088:5.3.23] 在 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal (RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.23.8820288:808] web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.23.jar:5.3.23] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1071 ) ~[spring-webmvc-5.3.23.jar:5.3.23] 在 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:964) ~[spring-webmvc-5.3.23.88202828:964] 或.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.23.jar:5.3.23] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[春天-我們 BMVC-5.3.23.jar:5.3.23]在Javax.Servlet.http.HTTPSERVET.ServeT.Service(httpservlet.httpservlet.httpservlet.88213246945588:655) servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.23.jar:5.3.23] 在 javax.servlet.http.HttpServlet.service(HttpServlet.8821em3246945888)[: -9.0.65.jar:4.0.FR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.65.jar:9.0.65] at org.apache.catalina .core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.65.jar:9.0.65] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[ tomcat-embed-websocket-9.0.65.jar:9.0.65] 在 org.apache.catalina.core.ApplicationFilterC hain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.65.jar:9.0.65] 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFiltercatbedem-9.0.65.jar:9.0.65) -core-9.0.65.jar:9.0.65] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:111) ~[spring-web-5.3.23.jar:5.3.23] at org.apache.catalina 。 tomcat-embed-core-9.0.65.jar:9.0.65] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:337) ~[spring-security-web-5.7.3.jar:5.7.3 ] 在 org.springframework.security.web.access.inter cept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115) ~[spring-security-web-5.7.3.jar:5.7.3] at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:81 ) ~[spring-security-web-5.7.3.jar:5.7.3] 在 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:346) ~[spring-security320.web87:85.7 5.7.3] 在 org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:122) ~[spring-security-web-5.7.3.jar:5.7.3] 在 org.springframework.security.88365850.86899 access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:116) ~[spring-security-web-5.7.3.jar:5.7.3] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java: 346) .3] at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:81) ~[spring-security-web-5.7.3.jar:5.7.3] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain .doFilter(FilterChainProxy.java:346) ~[spring-security-web-5.7.3.jar:5.7.3] 在 org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthentication2088-spring182.86) security-web-5.7.3.jar:5.7.3] 在 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:346) ~[spring-security-web-5.7.128.78305:882]組織.springf ramework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:149) ~[spring-security-web-5.7.3.jar:5.7.3] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy .java:346) ~[spring-security-web-5.7.3.jar:5.7.3] 在 org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.88213246945588:web-security) 5.7.3.jar:5.7.3] at org.springframework.security.web.filterchainproxy $ virtualfiltroxain.dofilter.dofilter.dofilter(filterChainProxy.8882132469469488888888888888888888888888888888888888888888888.8888888888.466) security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:166) ~[spring-security-web-5.7.3.jar:5.7.3] 在 org.springframework.88365508.68988.Refilter questFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.23.jar:5.3.23] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:346) ~[spring-security -web-5.7.3.jar:5.7.3] 在 org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter.doFilterInternal(DefaultLogoutPageGeneratingFilter.java:58) ~[spring-security-web-5.71.37888:5.7137882] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.23.jar:5.3.23] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy. java:346) ~[spring-security-web-5.7.3.jar:5.7.3] 在 org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.882132848:8:9458) ring-security-web-5.7.3.jar:5.7.3] 在 org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:223) ~[spring-security-web-8:920.288:223] .3] 在 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:346) ~[spring-security-web-5.7.3.jar:5.7.3] 在 org.8spring8auframe365.security8 .AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:223) ~[spring-security-web-5.7.3.jar:5.7.3] at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:217) ~[ spring-security-web-5.7.3.jar:5.7.3] 在 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:346) ~[s pring-security-web-5.7.3.jar:5.7.3] 在 org.auxpolice.filters.JwtRequestFilter.doFilterInternal(JwtRequestFilter.java:60) ~[類/:na] 在 org.springframework.web.filterFilterFilter.doRequestFilter.DoFilterInternal (曾經PerrequestFilter.java:117) 5.7.3.jar:5.7.3] 在 org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:103) ~[spring-security-web-5.7.3.882028789010838]:5 org springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:89) ~[spring-security-web-5.7.3.jar:5.7.3] 在 org.springframework.security.web.FilterFilterFilterProxyChain.FilterChain (FilterChainProxy.java:346) ~[spring-security-web-5.7.3.882028 78901088:5.7.3] 在 org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:91) ~[spring-web-5.3.23.jar:5.3.23] 在 org.springframework.8868365.jar:5.3.23] doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.23.jar:5.3.23] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:346) ~[spring-security-web -5.7.3.jar:5.7.3] at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90) ~[spring-security-web-5.7.3.jar:5.7.3] at org.springframework.security .web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75) ~[spring-security-web-5.7.3.jar:5.7.3] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[彈簧網絡 5.3.23。 jar:5.3.23] 在 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:346) ~[spring-security-web-5.7.3.8820288:85888:346) ~[spring-security-web-5.7.3.8820288:85888:346] or web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:112) ~[spring-security-web-5.7.3.jar:5.7.3] at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:82 ) ~[spring-security-web-5.7.3.jar:5.7.3] 在 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:346) ~[spring-security320.web87:85.7 5.7.3] 在 org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:55) ~[spring-security-web-5.7.3.jar:5.7.3] 在 o rg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.23.jar:5.3.23] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java :346) ~[spring-security-web-5.7.3.jar:5.7.3] at org.springframework.security.web.session.DisableEncodeUrlFilter.doFilterInternal(DisableEncodeUrlFilter.java:42) ~[spring-security-web-5.7.3.jar: 5.7.3] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.23.jar:5.3.23] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain. doFilter(FilterChainProxy.java:346) ~[spring-security-web-5.7.3.jar:5.7.3] 在 org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy-web-5.7.3.jar:5.7.3] - 5.7.3.jar:5.7.3] at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:186) ~[spring-security-web-5.7.3.jar:5.7.3] at org.springframework.web. filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:354) ~[spring-web-5.3.23.jar:5.3.23] at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:267) ~[spring-web -5.3.23.jar:5.3.23] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.65.jar:9.0.65] at org.apache.catalina .core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.65.jar:9.0.65] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[彈簧網-5.3.23.jar :5.3.23] at org.springframework.web.filter.onceperrequestfilter.dofilter(Anmerrequestfilter.java:117) (ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.65.jar:9.0.65] 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.8821324~cattom-core-94588) 9.0.65.jar:9.0.65] at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.23.jar:5.3.23] at org.springframework.web.filter. AnmerQuestFilter.dofilter(ANSERPERREQUESTFILTER.java:117) -9.0.65.jar:9.0.65] 在 org.8835283960 2088.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.65.jar:9.0.65] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201 ) ~[spring-web-5.3.23.jar:5.3.23] 在 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.23.882013.8789:5.3.23.882028789] .apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.65.jar:9.0.65] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 162) ~[tomcat-embed-core-9.0.65.jar:9.0.65] 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) ~[tomcat-embed120.88:92.06 .65] 在 org.apache.catalina.core.Stand ardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.65.jar:9.0.65] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core -9.0.65.jar:9.0.65] at org.8apache.CATALINA.CORE.CORE.CORE.STANDARDHOSTVALVE.INVOKE(StandardHostvalve.8821324694588:135) valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.65.jar:9.0.65] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed -core-9.0.65.jar:9.0.65] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) [tomcat-embed-core-9.0.65.jar:9.0.65] at org.apache. coyote.http11.Http11Processor.service(Http11Processor.java:399) [tomcat-embed-core-9.0.65.jar:9. 0.65] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.65.jar:9.0.65] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java :890) [tomcat-embed-core-9.0.65.jar:9.0.65] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1789) [tomcat-embed-core-9.0.65.jar: 9.0.65] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.65.jar:9.0.65] at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.65.jar:9.0.65] at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core- 9.0.65.jar:9.0.65] 在 org.apache.8824537 1585288.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)[tomcat-embed-core-9.0.65.jar:9.0.65] 在 java.lang.Thread.run(未知來源)[na:1.8。 0_331]
我到處都看過,但找不到如何處理的示例。
這是我的 object:
package org.auxpolice.model;
import java.sql.Blob;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.sql.rowset.serial.SerialBlob;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartFile;
public class Upload
{
private long uploadId;
public long getUploadId()
{
return this.uploadId;
}
public void setUploadId(long uploadId)
{
this.uploadId = uploadId;
}
private long uploadTypeId;
public long getUploadTypeId()
{
return this.uploadTypeId;
}
public void setUploadTypeId(long uploadTypeId)
{
this.uploadTypeId = uploadTypeId;
}
private Date dateEntered;
public Date getDateEntered()
{
return this.dateEntered;
}
public void setDateEntered(Date dateEntered)
{
this.dateEntered = dateEntered;
}
private String description;
public String getDescription()
{
return this.description;
}
public void setDescription(String description)
{
this.description = description;
}
private SerialBlob fileBlob;
public SerialBlob getFileBlob()
{
return this.fileBlob;
}
public void setFileBlob(SerialBlob fileBlob)
{
this.fileBlob = fileBlob;
}
private long enteredBy;
public long getEnteredBy()
{
return this.enteredBy;
}
public void setEnteredBy(long enteredBy)
{
this.enteredBy = enteredBy;
}
private String updatedTimestamp;
public String getUpdatedTimestamp()
{
return this.updatedTimestamp;
}
public void setUpdatedTimestamp(String updatedTimestamp)
{
this.updatedTimestamp = updatedTimestamp;
}
private Blob blob;
public Blob getBlob()
{
return this.blob;
}
public void setBlob(Blob blob)
{
this.blob = blob;
}
private MultipartFile file;
public MultipartFile getFile()
{
return this.file;
}
public void setFile(MultipartFile file)
{
this.file = file;
}
private String filename;
public String getFilename()
{
return this.filename;
}
public void setFilename(String filename)
{
this.filename = filename;
}
private Date dateEntered1;
public Date getDateEntered1()
{
return this.dateEntered1;
}
public void setDateEntered1(Date dateEntered1)
{
this.dateEntered1 = dateEntered1;
}
private Date dateEntered2;
public Date getDateEntered2()
{
return this.dateEntered2;
}
public void setDateEntered2(Date dateEntered2)
{
this.dateEntered2 = dateEntered2;
}
private String hasChildren;
public String getHasChildren()
{
return this.hasChildren;
}
public void setHasChildren(String hasChildren)
{
this.hasChildren = hasChildren;
}
private String unreadOnly;
public String getUnreadOnly()
{
return this.unreadOnly;
}
public void setUnreadOnly(String unreadOnly)
{
this.unreadOnly = unreadOnly;
}
public Upload()
{
this.setDateEntered(new Date(System.currentTimeMillis()));
this.setEnteredBy(0);
this.setUploadId(0);
this.setUploadTypeId(0);
this.setFileBlob(null);
this.setFile(null);
this.setFilename(StringUtils.EMPTY);
this.setDescription(StringUtils.EMPTY);
this.setDateEntered1(null);
this.setHasChildren(StringUtils.EMPTY);
this.setDateEntered2(null);
this.setBlob(null);
this.setUnreadOnly(StringUtils.EMPTY);
}
}
`
這是我的 rest controller 端點方法:
@GetMapping(value = "/getSingle" + "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Upload> getOne(@PathVariable String id, @RequestParam long officerId)
{
if (id.length() == 0)
return new ResponseEntity<Upload>(HttpStatus.NOT_FOUND);
List<Upload> arrayList = this.auxPoliceService.getUpload(officerId, Long.parseLong(id));
if (arrayList.size() == 0)
return new ResponseEntity<Upload>(HttpStatus.NOT_FOUND);
Upload singleRow = arrayList.get(0);
return new ResponseEntity<Upload>(singleRow, HttpStatus.OK);
}```
無法序列化 Blob(可能還有 SerialBlob),因為它是對 DB 列的引用。
使用以下內容獲取列的 byte[] 內容:
Blob blob = rs.getBlob("SomeDatabaseField");
int blobLength = (int) blob.length();
byte[] blobAsBytes = blob.getBytes(1, blobLength);
blob.free();
現在一個 byte[] 也不能被序列化,因為不是所有的字符都是可讀的,所以它需要轉換為文本字符串。 標准的方式是base 64編碼:
String encodedString = Base64.getEncoder().encodeToString(blobAsBytes);
現在您有一個字符串字段,可以包含在 JSON object 中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.