Using jackson API, I am trying to convert java object to json string. I have gone through several posts but not able to through the below stack-trace.
com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.imc.idm.data.request.DirectoryDetailData["logoImage"]->org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile["inputStream"]->java.io.FileInputStream["fd"])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:284)
at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1110)
at com.fasterxml.jackson.databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1135)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69)
My code is similar to this one below:
public class Infomation {
private MultipartFile img;
private Manufacture manufacture;
private List<Long> otherVal1;
private List<MyCustomClass> otherVal2;
}
Component :
ObjectMapper objectMapper = new ObjectMapper();
final String jsonString = objectMapper.writeValueAsString(infomationObject);
final MyDTO myDto = MyDTO.newBuilder().withValue(jsonString).build();
dataRepository.save(myDto);
Serializable interface/marker is not implemented in MultipartFile .
If you have Spring Web in your dependencies, you can use CommonsMultipartFile as it implements Serializable and MultipartFile.
For more information, please see Commons Multipart File Java API
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.