Kevin
Kevin

Reputation: 187

How to write a Jackson pojo class for a json object like a javascript object literal

I have a Modules class that contains a list of Module, the normal jackson json would look like:

 {  
       "modules" : [

          {
                "name" :  "module1" ,
                "file" : "file1"
            },

           {
              "name" : "module2" ,
              "file" : "file2" 
          }
        ]
    }

But I need the json file to be like this:

{  
   "modules" : {

      "module1" : {
           "file" : "file1"
        },

      "module2" : {
          "file" : "file2" 
      }
    }
}

Is there an easy way to configure/construct the pojo classes to achieve what I want without a custom deserializer? Thanks

Upvotes: 0

Views: 366

Answers (1)

Mike Thomsen
Mike Thomsen

Reputation: 37506

It's been a while since I've done anything with Jackson, but if you store the objects in a HashMap<String, ObjectType> that might do it. Otherwise yes, a custom deserializer would be necessary.

Upvotes: 2

Related Questions