public ArrayNode casMovie(Collection<Movie> movies_,ObjectMapper mapper){
ArrayNode array = mapper.createArrayNode();
for (Movie m : movies_) {
m.inicialitzarArray();
JsonNode node = mapper.createObjectNode();
((com.fasterxml.jackson.databind.node.ObjectNode) node).put("id", m.getId());
((com.fasterxml.jackson.databind.node.ObjectNode) node).put("itemType", "Movie");
((com.fasterxml.jackson.databind.node.ObjectNode) node).put("name", m.getName());
((com.fasterxml.jackson.databind.node.ObjectNode) node).put("year", m.getYear());
array.add(node);
}
return array;
}
public ArrayNode casSerie(Collection<Seria> series_,ObjectMapper mapper){
ArrayNode array = mapper.createArrayNode();
for (Seria m :series_) {
m.inicialitzarArray();
JsonNode node = mapper.createObjectNode();
((com.fasterxml.jackson.databind.node.ObjectNode) node).put("id", m.getId());
((com.fasterxml.jackson.databind.node.ObjectNode) node).put("itemType", "Seria");
((com.fasterxml.jackson.databind.node.ObjectNode) node).put("name", m.getName());
((com.fasterxml.jackson.databind.node.ObjectNode) node).put("year", m.getYear());
array.add(node);
}
return array;
}
我有不同的typesOfFilter
所以我不会重复任何代码来创建JSON。我做了一些研究,发现存在将ArrayNode添加到ArrayNode的函数。这是电话addall
。但我得到一个例外:
{"type":"API error","message":"RESTEASY003200: Could not find message body reader for type: org.jboss.resteasy.util.Types$1@2e8f240e of content type: */*"}"
以下是我获得例外的代码。
else if (typeFilter.equals("media")){
sr.movies = ms.getMovieByName(name);
sr.movies.size();
ArrayNode array = casMovie(sr.movies,mapper);
ArrayNode arrayNode2 = casSerie(sr.series,mapper);
ArrayNode arra4 = array.addAll(arrayNode2);//EXCEPTION
return buildResponse(arra4);