cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

extract field name from mandatoryAttributesvalidator

Former Member
0 Kudos
287

Hi,

How to extract field name, tablename from mandatoryAttributesvalidator. I need to send friendly message as response to the model creation request. Want to avoid building custom validator to check mandatory data since out-of-box logic is already available, however I need to send the field name as separate field and message (missing value) as separate field in response.

Example, from the below exception thrown by hybris, I need to extract the field name ‘name’ from below message and send that in separate field as below:

de.hybris.platform.servicelayer.exceptions.ModelSavingException: [de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator@3eef167f]:missing values for [fieldName] in model TableNameModel () to create a new TableName

i need to send below as response:

"message": "missing value/mandatory field", "field": "fieldName" "code": "0001"

or

"message": "missing value/mandatory field", "field": "TableName.fieldName" "code": "0001"

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Malini,

ModelSavingException, as all ValidationExceptions, is extending Throwable class. Unfortunately it doesn't provide method to extract specific values, so you would have to use custom validator.
Another option would be parsing the exception message and extracting fields you need.

Hope this helps and Best Regards,