jackson- 对象列表 com.fasterxml.jackson.core.io.JsonEOFException:字段名称中的输入意外结束?

jackson- List of objects com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input in field name?

我正在做一个自动反序列化我收到的 JSON 字符串的程序,问题是我收到 JSONObjectMapper 在 Java 对象中无法做到这一点。

  "Trazado": [
    {
      "Historial": [
        {
          "Longitude": 454353,
          "Latitude": 32423
        },
        {
          "Longitude": 454353,
          "Latitude": 32423
        },
        {
          "Longitude": 454353,
          "Latitude": 32423
        }
      ]
    },
    {
      "Historial": [
        {
          "Longitude": 454353,
          "Latitude": 32423
        }
      ]
    }
  ],

程序显示此异常:

com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input in field name

我定义了 类,就像我在 https://www.jsonschema2pojo.org/

中定义的那样
-----------------------------------com.example.DenmJson.java-----------------------------------

package com.example;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DenmJson {

private List<Trazado> trazado = new ArrayList<Trazado>();
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**
* No args constructor for use in serialization
*
*/
public DenmJson() {
}

/**
*
* @param trazado
*/
public DenmJson(List<Trazado> trazado) {
super();
this.trazado = trazado;
}

public List<Trazado> getTrazado() {
return trazado;
}

public void setTrazado(List<Trazado> trazado) {
this.trazado = trazado;
}

public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}
-----------------------------------com.example.Historial.java-----------------------------------

package com.example;

import java.util.HashMap;
import java.util.Map;

public class Historial {

private Integer longitude;
private Integer latitude;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**
* No args constructor for use in serialization
*
*/
public Historial() {
}

/**
*
* @param latitude
* @param longitude
*/
public Historial(Integer longitude, Integer latitude) {
super();
this.longitude = longitude;
this.latitude = latitude;
}

public Integer getLongitude() {
return longitude;
}

public void setLongitude(Integer longitude) {
this.longitude = longitude;
}

public Integer getLatitude() {
return latitude;
}

public void setLatitude(Integer latitude) {
this.latitude = latitude;
}

public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}
-----------------------------------com.example.Trazado.java-----------------------------------

package com.example;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Trazado {

private List<Historial> historial = new ArrayList<Historial>();
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**
* No args constructor for use in serialization
*
*/
public Trazado() {
}

/**
*
* @param historial
*/
public Trazado(List<Historial> historial) {
super();
this.historial = historial;
}

public List<Historial> getHistorial() {
return historial;
}

public void setHistorial(List<Historial> historial) {
this.historial = historial;
}

public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}

假设您需要将 JSON 字符串转换为对象列表:

private ObjectMapper objectMapper = new ObjectMapper();
List<Trazado> trazados = objectMapper.readValue(json , new TypeReference<List<Trazado>>(){});