Java 无法反序列化<;的实例;数据模型>;启动外\u对象标记
我面临着Spring和Jackson的问题。我试图从中获取输入。我已经使用 模型是Java 无法反序列化<;的实例;数据模型>;启动外\u对象标记,java,json,spring,jackson,Java,Json,Spring,Jackson,我面临着Spring和Jackson的问题。我试图从中获取输入。我已经使用 模型是 package io.github.mat3e.earthquake.jsonObject; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty
package io.github.mat3e.earthquake.jsonObject;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.List;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"type",
"metadata",
"features",
"bbox"
})
public class DataModel {
@JsonProperty("type")
private String type;
@JsonProperty("metadata")
private Metadata metadata;
@JsonProperty("features")
private List<Feature> features = null;
@JsonProperty("bbox")
private List<Double> bbox = null;
@JsonProperty("type")
public String getType() {
return type;
}
@JsonProperty("type")
public void setType(String type) {
this.type = type;
}
@JsonProperty("metadata")
public Metadata getMetadata() {
return metadata;
}
@JsonProperty("metadata")
public void setMetadata(Metadata metadata) {
this.metadata = metadata;
}
@JsonProperty("features")
public List<Feature> getFeatures() {
return features;
}
@JsonProperty("features")
public void setFeatures(List<Feature> features) {
this.features = features;
}
@JsonProperty("bbox")
public List<Double> getBbox() {
return bbox;
}
@JsonProperty("bbox")
public void setBbox(List<Double> bbox) {
this.bbox = bbox;
}
}
感谢@Willem和@mkarasik的帮助: 我在代码中做了以下更改
@GetMapping("/3")
public String getCostam() {
RestTemplate rest = new RestTemplate();
ResponseEntity<DataModel> responseEntity = restTemplate.getForEntity(url2, DataModel.class);
MediaType contentType = responseEntity.getHeaders().getContentType();
HttpStatus statusCode = responseEntity.getStatusCode();
System.out.println(responseEntity
.getBody().getFeatures());
return statusCode.toString();
}
谢谢你们的帮助。我得到了我需要的
现在我想从前端映射参数,以将其提供给后端,而不是硬编码字符串。您的错误来自以下行:
ResponseEntity ResponseEntity=restTemplate.getForEntity(url2,DataModel[].class)
看起来响应不是数据模型的数组
是,它不是数组。尝试DataModel[].class而不是DataModel.classEverything。谢谢你的帮助。我还能做什么?
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `[Lio.github.DataModel;` out of START_OBJECT token
at [Source: (PushbackInputStream); line: 1, column: 1]
@GetMapping("/3")
public String getCostam() {
RestTemplate rest = new RestTemplate();
ResponseEntity<DataModel> responseEntity = restTemplate.getForEntity(url2, DataModel.class);
MediaType contentType = responseEntity.getHeaders().getContentType();
HttpStatus statusCode = responseEntity.getStatusCode();
System.out.println(responseEntity
.getBody().getFeatures());
return statusCode.toString();
}
@Override
public String toString() {
return properties.getPlace();
}