{8.1.0-updated, 8.1.2-updated} @Beanc Annotation

The {@link oaj.annotation.Beanc @Beanc} annotation is used to map constructor arguments to property names on bean with read-only properties. Since method parameter names are lost during compilation, this annotation essentially redefines them so that they are available at runtime.

The definition of a read-only bean is a bean with properties with only getters, like shown below:

// Our read-only bean. public class Person { private final String name; private final int age; @Beanc(properties="name,age"}) public Person(String name, int age) { this.name = name; this.age = age; } // Read only properties. // Getters, but no setters. public String getName() { return name; } public int getAge() { return age; } }

// Parsing into a read-only bean. String json = "{name:'John Smith',age:45}"; Person p = JsonParser.DEFAULT.parse(json); String name = p.getName(); // "John Smith" int age = p.getAge(); // 45

Beans can also be defined with a combination of read-only and read-write properties.

The {@link oaj.annotation.Name @Name} annotation can also be used instead of @Beanc(properties):

@Beanc public Person(@Name("name") String name, @Name("age") int age) { this.name = name; this.age = age; }

If neither @Beanc(properties) or @Name is used to identify the bean property names, we will try to use the parameter names if they are available in the bytecode.