找不到类 java.io.ByteArrayInputStream 的序列化器

2023-11-25

从 openfire Rest api 获取用户实体时,我收到以下错误消息。 (我用 openfire Restapi 端点包装我的 Api 端点。)

"error": "内部服务器错误", “异常”:“org.springframework.http.converter.HttpMessageNotWritableException”, "message": "无法写入 JSON: 找不到类 java.io.ByteArrayInputStream 的序列化器,并且没有发现用于创建 BeanSerializer 的属性(为避免异常,请禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS);嵌套异常为 com.fasterxml.jackson.databind.JsonMappingException :没有找到类 java.io.ByteArrayInputStream 的序列化器,也没有发现创建 BeanSerializer 的属性(为避免异常,禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过引用链:com.mashape.unirest.http.HttpResponse[\"rawBody\"]) “, “路径”:“/userInfo/user2”

代码如下。

String  host ="http://abdul01anpi01:9090" ;
String userEndPoint = "/plugins/restapi/v1/users" ;
String apiURL = host+userEndPoint ;
HttpResponse<JsonNode> response =null;

response = Unirest.get(apiURL +"/{username}").header("accept", "application/json").header("Content-Type", "application/json").routeParam("username",String.valueOf(username)).asJson();

响应的预期输出如下。

{
    "username": "user2",
    "name": "user2",
    "properties": null
}

请提供建议,我们将不胜感激。


发帖者找到了解决方案并将其发布在评论中。由于已经过去了几年,我认为可能值得复制作为实际答案:

@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(mapper);
    return converter;
}

让我添加正在设置的标志的描述false :

/**
 * Feature that determines what happens when no accessors are
 * found for a type (and there are no annotations to indicate
 * it is meant to be serialized). If enabled (default), an
 * exception is thrown to indicate these as non-serializable
 * types; if disabled, they are serialized as empty Objects,
 * i.e. without any properties.
 *<p>
 * Note that empty types that this feature has only effect on
 * those "empty" beans that do not have any recognized annotations
 * (like <code>@JsonSerialize</code>): ones that do have annotations
 * do not result in an exception being thrown.
 *<p>
 * Feature is enabled by default.
 */
FAIL_ON_EMPTY_BEANS
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

找不到类 java.io.ByteArrayInputStream 的序列化器 的相关文章

随机推荐