ADF BC REST service - Type Mapping

JDev: 12.2.1.3.0

This article talks about a powerful, yet under-utilized, feature of ADF BC - the data type mapping. Oracle ADF provides this feature to generate a runtime mapping between a View Object's String attribute and a Web Service's (both SOAP and REST) Boolean attribute.

The most popular use-case for this feature is to map a Boolean Active/Inactive flag from the service to a Yes/No value on the View Object. By default, ADF provides 3 mappings, which cover the following scenarios:

1. oracle.jbo.valuemaps.BooleanYNPropertySet - maps Y/N to true/false.
2. oracle.jbo.valuemaps.BooleanTFPropertySet - maps T/F to true/false.
3. oracle.jbo.valuemaps.Boolean10PropertySet - maps 1/0 to true/false.

These property sets are in adfm.jar, which is part of the ADF Model Runtime library.

The advantage of using a type mapping is a two-way binding - you may pass the String as well as the Boolean value in the payload, and the type mapper automatically translates to the required value to be displayed on the service, or stored in the database. This becomes extremely useful when such attributes are mapped to a UI attribute such as ADF's selectBooleanCheckbox or JET's switch, which need boolean values.

To demonstrate this, I have added an ACTIVE_FLAG column on the HR schema's EMPLOYEES table, which has either Y or N value. This attribute has a Type Mapping set to BooleanYNPropertySet.


When we run the service, we see the following data in the JSON response:


The Y/N values of ACTIVE_FLAG column have been transformed into true/false in the ActiveFlag service attribute. The ADF or JET UI can use this transformation to display a component supporting boolean.


The other major advantage is two-way transformation. This means that, while POSTing or PATCHing to my service, I can send either of the boolean or the string value.



Custom Boolean Mappers:

As an extension to this article, it is also worthwhile to mention that you may also create your own custom property set to map your own use-case to a boolean value. To do this, you need to create a new Property Set from New > ADF Business Components > Property Set, and map your custom values to boolean fields.


In the above property set, I have reversed the conditions to map N to true and Y to false. You would need to provide the fully qualified name of this property set in the TypeValueMapPropertySet of the entity or view attribute.


However, unfortunately, this does not work as expected in REST services created with JDev 12.2.1.2.0 or 12.2.1.3.0. Even with the custom type-value-map, we continue to get the String value in the response. We will be logging a bug with Oracle Support soon, and I will update this article accordingly.

It does work with Oracle's internal fusion JDeveloper version, and also when you create a SOAP service, as demonstrated below:

The ActiveFlag values are now reversed

Cheers!

Comments