有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java将嵌套的Json对象反序列化为Java对象

我在反序列化一些嵌套的Json时遇到了一些问题

要反序列化的json:Json Link Here

ObjectMapper objectMapper = new ObjectMapper();
ListRandomBixi bixi = objectMapper.readValue(url, ListRandomBixi.class);

还有两个班:

class ListRandomBixi{
@JsonProperty("stations")
ArrayList<RandomBixi> arrayBixi;
@JsonProperty("schemeSuspended")
boolean schemeSuspended;
@JsonProperty("timestamp")
long timeStanp;

@JsonCreator
public ListRandomBixi(@JsonProperty("stations") ArrayList<RandomBixi> arrayBixi, @JsonProperty("schemeSuspended") boolean schemeSuspended, @JsonProperty("timestamp") long timeStanp) {
  this.arrayBixi = arrayBixi;
  this.schemeSuspended = schemeSuspended;
  this.timeStanp = timeStanp;
}
      getters & setters....
}
class RandomBixi {
@JsonProperty("id")
int id;
@JsonProperty("s")
String nom;
@JsonProperty("n")
int idTerminal;
@JsonProperty("st")
int etatStation;
@JsonProperty("b")
boolean bloque;
@JsonProperty("su")
boolean suspendue;
@JsonProperty("m")
boolean hs;
@JsonProperty("lu")
int lu;
@JsonProperty("lc")
int lc;
@JsonProperty("la")
String latitude;
@JsonProperty("lo")
String longitude;
@JsonProperty("da")
int borneDispo;
@JsonProperty("dx")
int dx;
@JsonProperty("ba")
int bixiDispo;
@JsonProperty("bx")
int bx;

  getters ans setters....
}

我得到这个错误:com。fasterxml。杰克逊。数据绑定。JsonMappingException:无法识别的类型:[null]

有什么建议吗

谢谢


共 (1) 个答案

  1. # 1 楼答案

    blabla1blabla2的值也是文本。但是您需要声明类字段是booleanlong。这会导致错误。让我们将blabla1blabla2的类型更改为String