从openfire rest api获取用户实体时收到以下错误消息。 (我用openfire Restapi端点封装了我的Api端点。)
“错误”:“内部服务器错误”, “exception”:“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 \”]) ” “path”:“/ usersInfo / 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
}
请告知,任何帮助表示赞赏。
答案 0 :(得分:1)
张贴者找到了解决方案,并将其张贴在评论中。既然已经过去了几年,所以我认为可以将它复制为实际答案:
public function deleteProductImageName($id) {
if(Auth::check()) {
$products = Product::where('id', $id)->first();
foreach($products as $p) {
if(($products->user_id == Auth::user()->id) && ($products->id == $id)) {
$product = Product::where('user_id', Auth::user()->id)
->where('id', $id)->first();
$filename_index = $product->filename;
echo $filename_index; '<br/>';
echo $filename_index . '[' . $index . ']';
}
}
} else {
Session::flash("message", "OOPS! You dont have permission to delete the items. Please login first.");
return redirect("/register-user");
}
}
让我为正在设置为@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(mapper);
return converter;
}
的标志添加描述:
false
答案 1 :(得分:0)
它有效,添加一个ResourceHttpMessageConverter!
@Configuration
public class EirExceptionConfig extends WebMvcConfigurerAdapter {
@Autowired
ObjectMapper objectMapper;
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(EirException.class, new EirExceptionJackson2Serializer());
objectMapper.registerModule(simpleModule);
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper);
converters.add(new ResourceHttpMessageConverter());
converters.add(converter);
}
}
答案 2 :(得分:-1)
解决此问题的另一种方法是忽略返回类型为ByteArrayInputStream
的属性,例如,您可以修饰此类:
class Frodo {
private bytes[] value;
public Frodo(bytes[] value) {
this.value = value;
}
public ByteArrayInputStream getFoo() throws IOException {
return new ByteArrayInputStream(value());
}
public void setFoo(ByteArrayInputStream streamData) {
// set value from streamData
}
}
像这样:
@JsonIgnoreProperties(value = { "foo" })
class Frodo {
private bytes[] value;
public Frodo(bytes[] value) {
this.value = value;
}
public ByteArrayInputStream getFoo() throws IOException {
return new ByteArrayInputStream(value());
}
public void setFoo(ByteArrayInputStream streamData) {
// set value from streamData
}
}
您还可以忽略多个属性:@JsonIgnoreProperties(value = { "foo", "anotherValue" })