Parthiban Manickam
Parthiban Manickam

Reputation: 155

Serialising a Java Map with Jackson

I am using Jackson library for serialising JSON,

having Serialising a Java Map, for ex, map<String,String> has

{<color, green>,<color, blue>}

I want this to be serialised as

"colormap":[{"key": "color":, "value":"green"}, {"key": "color:, "value":"blue"}]

but its always serialising as

"colormap":[{"color":"green"}, {"color:"blue"}]

Upvotes: 0

Views: 50

Answers (1)

Eric
Eric

Reputation: 194

Your output JSON is an array, not a map- Without looking at your code it's hard to tell what the underlying data structure is,but to do what you're looking for you might consider a class such as:

class Thing {
  private String key ;
  private String value ;
  /// add accessors as needed
}

and then declare your colormap as List<Thing>. This should seralize your data per your expectation.

Upvotes: 1

Related Questions