API를 사용하여 영양 정보를 가져 오는 Spring MVC 프로젝트에 문제가 있습니다. java.lang.IllegalArgumentException : 인수 유형 불일치가 중첩 예외를 계속 가져옵니다. 아래에 게시 된 JSON 응답 및 deserialization 프로세스에 대해 만든 클래스입니다.JSON의 비 직렬화, 불일치
public FullResponse search() throws ClientProtocolException, IOException{
CloseableHttpClient client = HttpClients.createDefault();
HttpGet getProducts = new HttpGet("https://api.nutritionix.com/v1_1/search/"+ value +"?results=0%3A6&cal_min=0&cal_max=50000&fields=item_name%2Citem_id&appId=ac23ceb3&appKey=API_KEY");
CloseableHttpResponse productResponse = client.execute(getProducts);
String entityString = EntityUtils.toString(productResponse.getEntity());
FullResponse test = new JSONDeserializer<FullResponse> ().deserialize(entityString,FullResponse.class);
return test;
}
이 전체 응답 클래스입니다 //
public class FullResponse {
String total_hits;
String max_score;
List<Hits> hits;
public FullResponse(){
}
public String getTotal_hits() {
return total_hits;
}
public void setTotal_hits(String total_hits) {
this.total_hits = total_hits;
}
public String getMax_score() {
return max_score;
}
public void setMax_score(String max_score) {
this.max_score = max_score;
}
public List<Hits> getHits() {
return hits;
}
public void setHits(List<Hits> hits) {
this.hits = hits;
}
}
// 이것은 내가
public class Hits {
String _index;
String _type;
String _id;
String _score;
List<Fields> fields;
public Hits(){
}
public String get_index() {
return _index;
}
public void set_index(String _index) {
this._index = _index;
}
public String get_type() {
return _type;
}
public void set_type(String _type) {
this._type = _type;
}
public String get_id() {
return _id;
}
public void set_id(String _id) {
this._id = _id;
}
public String get_score() {
return _score;
}
public void set_score(String _score) {
this._score = _score;
}
public List<Fields> getFields() {
return fields;
}
public void setFields(List<Fields> fields) {
this.fields = fields;
}
}
//
을 만든 히트 클래스입니다 그리고 이것은 내가 만든 내 필드 클래스입니다public class Fields {
String item_name;
public Fields(){
}
public String getField(){
return item_name;
}
public void setField(String name){
item_name=name;
}
}
goi 잘못하면 거대한 도움이 될 것입니다. 여기
내가 잘flexjson
을 모르는 요청
{
"total_hits":11025,
"max_score":11.122117,
"hits":[{
"_index":"nixproductionv13",
"_type":"item",
"_id":"513fceb375b8dbbc210000e4",
"_score":11.122117,
"fields":{"item_name":"Whole Milk - 1 tbsp"}},
{"_index":"nixproductionv13",
"_type":"item",
"_id":"513fceb375b8dbbc2100017b",
"_score":10.7038355,
"fields":{"item_name":"2% Milk - 1 cup"}},
{"_index":"nixproductionv13",
"_type":"item",
"_id":"513fceb375b8dbbc210000f3",
"_score":10.7038355,
"fields":{"item_name":"1% Milk - 1 cup"}},
{"_index":"nixproductionv13",
"_type":"item",
"_id":"513fceb375b8dbbc210000fb",
"_score":10.689078,
"fields":{"item_name":"Skim Milk - 1 cup"}},
{"_index":"nixproductionv13",
"_type":"item",
"_id":"513fceb375b8dbbc210000e3",
"_score":10.65872,
"fields":{"item_name":"Whole Milk - 1 fl oz"}},
{"_index":"nixproductionv13",
"_type":"item",
"_id":"513fceb375b8dbbc2100017a",
"_score":10.392,
"fields":{"item_name":"2% Milk - 1 quart"}}]}
전체 스택 추적을 게시하십시오. –