java - 意外的输入结束 : expected close marker for OBJECT

标签 java google-app-engine search jackson geopoints

我试图在我的 App Engine 应用程序中创建一个地理点,但是当我尝试反序列化它时,我收到了这条烦人的消息:

Uncaught exception from servlet
org.codehaus.jackson.JsonParseException: Unexpected end-of-input: expected close marker for OBJECT (from [Source: java.io.StringReader@1a21658; line: 1, column: 0]).

这是我的 JSON 代码:

{
    "id": 31,
    "name": "pepe",
    "mail": "p@p.com",
    "password": 123,
    "age":10,
    "birthday": "01-06-1991",
    "desc" : " bla bla",
    "gp": {
     "latitude": 64.124596,
     "longitude": -147.8632
     }
}

这是 geopoint 的声明和我自定义的反序列化方法:

GeoPoint gp;

public GeoPoint getGp() {
    return gp;
}

@JsonDeserialize(using = CustomGeoPintDeserializer.class)
public void setGp(GeoPoint gp) {
    this.gp = gp;
}

public  class CustomGeoPintDeserializer extends JsonDeserializer<GeoPoint> {

    @Override
    public GeoPoint deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {

        System.out.println("ENTRA");
        ObjectMapper mapper = new ObjectMapper();
        JsonNode actualObj = mapper.readValue(jsonParser.getText(), JsonNode.class);

        double latitude = actualObj.get("latitude").getDoubleValue();

        double longitude = actualObj.get("longitude").getDoubleValue();


        return new GeoPoint(latitude,longitude);
    }
}

最佳答案

对我来说,这是非常简单的解决方案。

我忘记在我的 SwaggerUI 请求中关闭括号:

{
    "jobGroup": "Authorizer-CCC",
    "jobName": "Authorizer-2NO5-101"

关于java - 意外的输入结束 : expected close marker for OBJECT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25526611/

相关文章:

java - 使用 elasticsearch 对文本进行分类

azure - 如何返回平均值 - Azure 认知搜索或语义搜索查询

java - 从多个列表中生成所有可能的组合

java - JUnit Suite 内的日志信息

java - 为什么我的 JPanel 在 JScrollPane 中不滚动?

java - 将外部 int 添加到操作监听器中

python - 如何将实时数据从我的生产 App Engine 应用程序获取到我的本地开发应用程序?

google-app-engine - 嵌套对象化事务是否保持原子性 - 或者它们是否有效

Python:捕获特定异常

c# - 将自定义搜索过滤器转换为动态 SQL