improved handling of null values when mapping entities to json

This commit is contained in:
2025-07-25 23:02:54 +02:00
parent 01a7389665
commit 3d81ddd3c5
15 changed files with 81 additions and 124 deletions

View File

@@ -216,7 +216,12 @@ public class ProjectModule extends BaseHandler implements ProjectService {
private boolean postProject(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException {
var json = json(ex);
if (!(json.has(NAME) && json.get(NAME) instanceof String name)) throw missingFieldException(NAME);
var description = json.has(DESCRIPTION) && json.get(DESCRIPTION) instanceof String d ? d : null;
String description = null;
if (json.has(DESCRIPTION)){
var desc = json.get(DESCRIPTION);
if (desc instanceof String d) description = d;
if (desc instanceof JSONObject nested && nested.has(SOURCE) && nested.get(SOURCE) instanceof String d) description = d;
}
Long companyId = null;
if (json.has(COMPANY_ID) && json.get(COMPANY_ID) instanceof Number number){
if (!companies.membership(number.longValue(), user.id())) throw forbidden("You are not a member of company {0}!",number);