ADF BC REST service - defaulting with CREATE method

JDev: 12.2.1.3.0

This is more like an update on my previous article - ADF BC REST - NULL and DEFAULT, where I spoke about the various ways null data can be defaulted via a REST API. However, there was one use case which I had missed - the CREATE method of EntityImpl.

There is an interesting behaviour which may be observed when, instead of  setting a default value declaratively on the entity attribute, we override the CREATE method of the EntityImpl subclass.

When a value is set in the create method, this value takes precedence, irrespective of whether we pass null, some value or don't pass the attribute in the payload at all.

To demonstrate this, I will set a value of 25000 for Salary attribute in the create method.

Developer Tip: Instances of subclasses should call super.create() before performing any operation.

And I will pass the below payloads:


For all the three payloads, the data gets saved with salary 25000, the value with which it was initialized in the create method, irrespective of the fact that I also have a declarative default value for the Salary entity attribute.


A simple check for not-null condition would allow you to set the desired value from your payload.


Cheers!

Comments

Post a Comment