Search code examples
jsonmaven-2jerseyjackson

Is there any way to override or update Jersey's Jackson version?


We're trying to use Jackson 1.5 to take advantage of some of the polymorphic handling it offers, but it appears that Jersey brings along it's own outdated version of Jackson (1.1.1). When testing Jersey serialized JSON, we get different results than when we serialize by hand in unit tests.

{
  "id": "40",
  "ticketProps": [{
    "id": "28",
    "field": {
      "id": "28",
      "name": "WXYZ",
      "strict": "false",
      "valueType": "STRING"
    },
    "value": "W"
  }, {
    "id": "29",
    "field": {
      "id": "29",
      "name": "SEAT",
      "strict": "false",
      "valueType": "STRING"
    },
    "value": "4A"
  }]
}

{
  "id": "40",
  "ticketProps": [{
    "id": "28",
    "field": {}
  }, {
    "id": "29",
    "field": {}
  }],
  "name": null
}

Unfortunately using Jackson 1.1.1 is not an option. Is there any way to get Jersey to use Jackson 1.5? Was thinking of trying to set it in the Jersey Config class or something...


Solution

  • If the maven POM for Jersey does not allow you to separate the Jackson dependency from the Jersey dependency, then you could get hold of the individual JARs manually, swapping out the Jackson 1.5.x JAR(s) for the 1.1.x one.

    Note that there's no guarantee that Jersey will work with the newer Jackson version. Jackson's API changed quite a lot around the 1.1 releases.