I have a bean with CommonsMultipartFile type field like so:
public class Placement implements Serializable {
private static final long serialVersionUID = 1L;
private long placementId;
private String type;
private String placement;
private transient CommonsMultipartFile fileData;
I have marked CommonsMultipartFile field as transient and trying to serialize to json using jackson library. But getting following error:
org.codehaus.jackson.map.JsonMappingException: No serializer found for class java.io.ByteArrayInputStream and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: nextag.travel.dashboard.model.Placement["fileData"]->org.springframework.web.multipart.commons.CommonsMultipartFile["inputStream"])
Any help/ suggestions would be highly appreciated.
It’s not clear how Jackson is being used, as no code or description was provided in the original question.
By default, Jackson skips all transient fields during serialization.
If there is a getter for the transient field, however, then by default Jackson includes it during serialization.
One configuration option to skip the getter is to just apply the @JsonIgnore annotation.
If it’s not possible or desirable to edit the original class definition to add the @JsonIgnore annotation, a Mix-In can be used.
Another approach is to mark the type to be skipped with
@JsonIgnoreType.