Jackson 与 CommonsMultipartFile 的序列化问题
我有一个带有 CommonsMultipartFile 类型字段的 bean,如下所示:
public class Placement implements Serializable {
private static final long serialVersionUID = 1L;
private long placementId;
private String type;
private String placement;
private transient CommonsMultipartFile fileData;
我已将 CommonsMultipartFile 字段标记为瞬态,并尝试使用 jackson 库序列化为 json。但出现以下错误:
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"])
任何帮助/建议将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前尚不清楚杰克逊是如何被使用的,因为原始问题中没有提供代码或描述。
默认情况下,Jackson 在序列化期间会跳过所有瞬态字段。
然而,如果瞬态字段有一个 getter,那么默认情况下 Jackson 在序列化过程中会包含它。
跳过 getter 的一种配置选项是仅应用 @JsonIgnore 注释。
如果不可能或不需要编辑原始类定义以添加 @JsonIgnore 注释,则 Mix-In可以使用。
另一种方法是使用
@JsonIgnoreType
标记要跳过的类型。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
.如果您不想序列化多部分文件,请将注释
@JsonIgnore
添加到该字段。您可以在此处阅读有关 bot jackson 注释的更多信息。
If you do not want to serialize the multipartfile then add the annotation
@JsonIgnore
to the field.You can read more abot jackson annotations here.