Java 输入意外结束:对象应为关闭标记

Java 输入意外结束:对象应为关闭标记,java,google-app-engine,search,jackson,geopoints,Java,Google App Engine,Search,Jackson,Geopoints,我正在尝试在我的应用程序引擎应用程序中创建一个地质点,但当我尝试对其进行反序列化时,我收到了一条恼人的消息: 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]

我正在尝试在我的应用程序引擎应用程序中创建一个地质点,但当我尝试对其进行反序列化时,我收到了一条恼人的消息:

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);
    }
}
GeoPoint-gp;
公共地质点getGp(){
返回总成;
}
@JsonDeserialize(使用=CustomGeoPintDeserializer.class)
公共无效集gp(地质点gp){
this.gp=gp;
}
公共类CustomGeoPintDeserializer扩展JsonDeserializer{
@凌驾
公共地理点反序列化(JsonParser、JsonParser、反序列化上下文、反序列化上下文)引发IOException、JsonProcessingException{
系统输出打印项次(“ENTRA”);
ObjectMapper mapper=新的ObjectMapper();
JsonNode actualObj=mapper.readValue(jsonParser.getText(),JsonNode.class);
double latitude=actualObj.get(“纬度”).getDoubleValue();
double longitude=actualbobj.get(“经度”).getDoubleValue();
返回新的地理点(纬度、经度);
}
}

看起来您的
GeoPoint
类有这样的构造函数:
公共GeoPoint(双纬度,双经度)
。在这种情况下,我们可以使用。我们必须创建额外的抽象类,在这个抽象类中,我们将提供
POJO
JSON
之间的映射

abstract class GeoPointMixIn {

    GeoPointMixIn(@JsonProperty("latitude") double latitude, @JsonProperty("longitude") double longitude) {

    }
}
简单用法:

ObjectMapper mapper = new ObjectMapper();
mapper.addMixInAnnotations(GeoPoint.class, GeoPointMixIn.class);

System.out.println(mapper.readValue(JSON, YourRootPojo.class));

正如您所见,您不必为
GeoPoint
类实现自定义反序列化程序。

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

我忘了在我的招摇过市请求中关闭括号,如下所示:

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

GeoPoint类看起来怎么样?这个类的包是什么?我需要使用哪个版本的jackson mapper.AddMixinNotations?我使用的是版本2.4.1(fasterxml),但我认为这个方法从版本2.0.0开始就存在了。