序列化后不能用 jersey 反序列化 json?

cannot deserialize json with jersey after serializing?

我有这个class:

public class StatsResult {



    private final EditorUrlGenerator editorUrlGenerator;
    private final LiveMapUrlGenerator liveMapUrlGenerator;

    public String saveDate;

    public Map<String, String> idsToEditorUrls;
    public Map<String, String> idsToLiveMapUrls;

    public List<String> nonIdenticalInstructions;
    public List<String> nonIdenticalRouteNames;

    public List<String> distanceLargeDeltaComparedToBL;
    public List<String> distanceSmallDeltaComparedToBL;

    //TODO: maybe array[Delta][]
    public List<String> timeLargeDeltaComparedToBL;
    public List<String> timeSmallDeltaComparedToBL;

    public List<Integer> idsWithHighLatency;

    public List<LatencyBulk> tillOneSecondBulks;
    public List<LatencyBulk> tillFiveSecondBulks;
    public LatencyBulk moreThanFiveSecondBulks;

我已经序列化一个实例并成功保存到文件。

稍后我尝试从该文件中读取并反序列化,但失败了。

org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class com.waze.routing.automation.dto.stats.StatsResult]: can not instantiate from JSON object (need to add/enable type information?)
    at [Source: src/main/resources/latency_recorder; line: 2, column: 3]

文件:

{
  "saveDate" : "04:26:20 06-Mar-02015",
  "idsToEditorUrls" : { },
  "idsToLiveMapUrls" : { },
  "nonIdenticalInstructions" : [ ],
  "nonIdenticalRouteNames" : [ ],
  "distanceLargeDeltaComparedToBL" : [ ],
  "distanceSmallDeltaComparedToBL" : [ ],
  "timeLargeDeltaComparedToBL" : [ ],
  "timeSmallDeltaComparedToBL" : [ ],
  "idsWithHighLatency" : [ ],
  "tillOneSecondBulks" : [ {
    "bulkName" : "[0,0.2) seconds",
    "ids" : [ ],
    "count" : 0,
    "countOfCurrentAndSlower" : 2
  }, {
    "bulkName" : "[0.2,0.4) seconds",
    "ids" : [ ],
    "count" : 0,
    "countOfCurrentAndSlower" : 2
  }, {
    "bulkName" : "[0.4,0.6) seconds",
    "ids" : [ "id:1 millis:563" ],
    "count" : 1,
    "countOfCurrentAndSlower" : 2
  }, {
    "bulkName" : "[0.6,0.8) seconds",
    "ids" : [ ],
    "count" : 0,
    "countOfCurrentAndSlower" : 1
  }, {
    "bulkName" : "[0.8,1) seconds",
    "ids" : [ ],
    "count" : 0,
    "countOfCurrentAndSlower" : 1
  } ],
  "tillFiveSecondBulks" : [ {
    "bulkName" : "[1,1.5) seconds",
    "ids" : [ "id:0 millis:1289" ],
    "count" : 1,
    "countOfCurrentAndSlower" : 1
  }, {
    "bulkName" : "[1.5,2) seconds",
    "ids" : [ ],
    "count" : 0,
    "countOfCurrentAndSlower" : 0
  }, {
    "bulkName" : "[2,2.5) seconds",
    "ids" : [ ],
    "count" : 0,
    "countOfCurrentAndSlower" : 0
  }, {
    "bulkName" : "[2.5,3) seconds",
    "ids" : [ ],
    "count" : 0,
    "countOfCurrentAndSlower" : 0
  }, {
    "bulkName" : "[3,3.5) seconds",
    "ids" : [ ],
    "count" : 0,
    "countOfCurrentAndSlower" : 0
  }, {
    "bulkName" : "[3.5,4) seconds",
    "ids" : [ ],
    "count" : 0,
    "countOfCurrentAndSlower" : 0
  }, {
    "bulkName" : "[4,4.5) seconds",
    "ids" : [ ],
    "count" : 0,
    "countOfCurrentAndSlower" : 0
  }, {
    "bulkName" : "[4.5,5) seconds",
    "ids" : [ ],
    "count" : 0,
    "countOfCurrentAndSlower" : 0
  } ],
  "moreThanFiveSecondBulks" : {
    "bulkName" : "5 seconds",
    "ids" : [ ],
    "count" : 0,
    "countOfCurrentAndSlower" : 0
  }
}

它会是什么?

我想,class StatsResult 有一个参数化的构造函数? (您添加到问题中的代码似乎已缩短)。如果是:

错误消息说,Jersey 想要创建 StatsResult 的实例 class,但找不到合适的构造函数。在大多数情况下,您只需向 class 添加一个无参数构造函数,这样 Jersey 就可以实例化它:

protected StatsResult() {
    // for jersey
}

当然,Jersey 不能为"editorUrlGenerator" 和"liveMapUrlGenerator" 设置值,因此您也需要在无参数构造函数中处理它们(赋值?)。