Skip to main content

@NameProperty Annotation

The @NameProperty annotation is used to identify a setter as a method for setting the name of a POJO as it's known by its parent object.

A commonly-used case is when you're parsing a JSON map containing beans where one of the bean properties is the key used in the map.

// JSON
{
id1: {name: 'John Smith', sex: 'M'},
id2: {name: 'Jane Doe', sex: 'F'}
}
public class Person {

@NameProperty
public String id; // Value gets assigned from object key

public String name;

public char sex;
}