2

I'm trying to parse some JSON containing a nested array. I'd like the array to map to a list of child objects within the parent I'm mapping. Here is the (slightly abbreviated) JSON and Java classes

JSON:

{
    "id": "12121212121",
    "title": "Test Object",
    "media$content": [
        {
            "plfile$audioChannels": 1,
            "plfile$audioSampleRate": 18000,
        },
        {
            "plfile$audioChannels": 2,
            "plfile$audioSampleRate": 48000,
        },
        {
            "plfile$audioChannels": 2,
            "plfile$audioSampleRate": 48000,
        }
    ]
}

Java classes

class MediaObject {
    @JsonProperty("id")
    private String id;

    @JsonProperty("title")
    private String title;

    @JsonProperty("media$Content")
    private List<MediaContent> mediaContent;

    ... getters/setters ...

}


class MediaContent {

    @JsonProperty("plfile$audioChannels")
    private int audioChannels;

    @JsonProperty("plfile$audioSampleRate")
    private int audioSampleRate;

    ... getters/setters ...
}

I'd like to be able to deserialize using annotations along with the standard mapper code, i.e. mapper.readValue(jsonString, MediaObject.class)

Everything works fine with the "id" and "title" fields, but my list of MediaContent objects always comes up null. This seems like something Jackson should be able to handle without much trouble, can anyone see what I'm doing wrong here?

user817851
  • 219
  • 1
  • 3
  • 10

1 Answers1

3

The name of the json field is wrong - the attribute is not media$Content, rather media$[c]ontent. Otherwise I do not see why it will not work.

Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
  • Well, this is a little embarrassing. I won't tell you how long I beat my head against this without realizing it was a case-sensitivity error. Thanks for spotting that. – user817851 Feb 07 '13 at 22:57