Updated the update action, to set a null value for fields that came in the request as empty string

This commit is contained in:
2022-09-27 13:28:13 -05:00
parent 833b1f9643
commit 3587cc0676
2 changed files with 25 additions and 4 deletions

View File

@ -403,9 +403,21 @@ public class QJavalinImplementation
Map<?, ?> map = context.bodyAsClass(Map.class);
for(Map.Entry<?, ?> entry : map.entrySet())
{
if(StringUtils.hasContent(String.valueOf(entry.getValue())))
String fieldName = ValueUtils.getValueAsString(entry.getKey());
Object value = entry.getValue();
if(StringUtils.hasContent(String.valueOf(value)))
{
record.setValue(String.valueOf(entry.getKey()), (Serializable) entry.getValue());
record.setValue(fieldName, (Serializable) value);
}
else if("".equals(value))
{
///////////////////////////////////////////////////////////////////////////////////////////////////
// if frontend sent us an empty string - put a null in the record's value map. //
// this could potentially be changed to be type-specific (e.g., store an empty-string for STRING //
// fields, but null for INTEGER, etc) - but, who really wants empty-string in database anyway? //
///////////////////////////////////////////////////////////////////////////////////////////////////
record.setValue(fieldName, null);
}
}