0

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);
4
  • make sure your classes are serializable, i mean they implements Serializable interface. Commented Nov 29, 2017 at 14:49
  • Do I need to serialize Infomation class only, because MultipartFile is the class present in apis. Commented Nov 29, 2017 at 14:52
  • What is objectMapper and what is infomationObject. Please provide more information Commented Nov 29, 2017 at 15:01
  • infomationObject is the object of Information class, which I am getting when do Post call. Commented Nov 29, 2017 at 15:16

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.