JsonAnySetter

I am using the Jackson JSON Lib in Java to process JSON. If you don’t know how JSON works in Ruby, you will like this project. Anyway. If you have dynamic JSON stream where the property names are not always the same, than you need the “@JsonAnySetter” Annotation. With that you can map dynamic Properties to a map.


private Map<String, Object> all = new HashMap<String, Object>();

@JsonAnySetter
public void set(String name, Object value) {
   all.put(name, value);
}

public Map<String, Object> getAll() {
   return all;
}

public void setAll(Map<String, Object> all) {
   this.all = all;
}

That worked out for me, for a String – String pair.

One thought on “JsonAnySetter

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s