{title:'Virtual Beans', updated:'9.0.0'}

The {@link oaj.BeanContext.Builder#disableInterfaceProxies()} setting (enabled by default) allows the Juneau parsers to parse content into virtual beans (bean interfaces without implementation classes).

For example, the following code creates an instance of the specified unimplemented interface:

| // Our unimplemented interface | public interface Address { | | String getStreet(); | void setStreet(String value); | | String getCity(); | void setCity(String value); | | StateEnum getState(); | void setState(StateEnum value); | | int getZip(); | void setZip(int value); | } | | // Our code | Address address = Json. to( | "{street:'123 Main St', city:'Anywhere', state:'PR', zip:12345}", | Address. class | ); | | int zip = address.getZip(); | address.setState(StateEnum. NY);

Getter and setter values can be any parsable values, even other virtual beans.

Under-the-covers, a virtual bean is simply a proxy interface on top of an existing {@link oaj.BeanMap} instance. From a programmatic point-of-view, they're indistinguishable from real beans, and can be manipulated and serialized like any other bean.

Virtual beans can also be created programmatically using the {@link oaj.BeanContext} class:

| Address address = BeanContext. DEFAULT.createSession().newBean(Address. class);