0

Using Jackson to interface to Amazon CloudSearch, which ingests data in the format SDF. Here is an example:

[ {
  "type" : "add",
  "id" : "images_to_search_csv_1",
  "version" : 1336526759,
  "lang" : "en",
  "fields" : {
    "content" : "http://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Timba%2B1.jpg/220px-Timba%2B1.jpg",
    "title" : "Simba",
    "source" : "wikipedia",
    "description" : "Simba the wolf dog.",
    "type" : "Image"
  }
}, {
  "type" : "add",
  "id" : "images_to_search_csv_2",
  "version" : 1336526760,
  "lang" : "en",
  "fields" : {
    "content" : "http://www.wolfzone1.com/photos/sedona-01d%20copy.jpg",
    "title" : "Wolf",
    "source" : "Wolf Zone",
    "description" : "Another wolf.",
    "type" : "Image"
  }
} ]

Notice that the fields are fields of the entity that you are submitting. So clearly, if you just bind that entity to the SDF class, you get the entity and then its fields but the structure of the file ends up different. Should I just write the code to output this by hand rather than have Jackson do it?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Rob
  • 11,446
  • 7
  • 39
  • 57

1 Answers1

0

You can write custom deserializers/serializers, to only write handlers for that portion manually; registration can be done globally for types, as well as on per-property basis. This way you can reduce amount of explicit work quite a bit. It is also possible to use multi-stage processing: first binding to something generic (Map, JsonNode), transform structure a bit, then convert to/from POJO (`ObjectMapper.convertValue()').

StaxMan
  • 113,358
  • 34
  • 211
  • 239
  • 1
    Yeah I found this. Turns out that there were other problems with their JSON, namely that it contained other JSON. The error messages in Jackson are not very precise. But I did get it to work. Thanks. – Rob May 10 '12 at 20:22
  • Actually, the above example was after I got it to show me the SDF, the results it sent back from the engine directly included things like brackets around the url, with quotes inside, which Jackson spat up on. – Rob May 10 '12 at 20:23