Java and JSON processing

Java and JSON processing

The best processor we've used is Jackson.


Use version 2 if possible.

Dynamic Beans

To add dynamic fields into your model, you can use the annotation @JsonAnyGetter on a method that returns a Map. This map will be serialized on the same level as the the other fields.

public class Person {
    private String name;
    private Map<String, Object> otherFields = new HashMap<String, Object>();

    public Map<String,Object> any() {
        return otherFields;

    public void set(String name, Object value) {
        otherFields.put(name, value);

    public String getName() {
        return name;

    public void setName(String name) { = name;
Person person = new Person();
person.set("age", 300);

// serialize
new ObjectMapper().writeValue(System.out, person);

The above will output


See sample/

Published: Friday, 30 January 2015