-1

Empty json object {} inside array is mapping to request and list is showing as size 1.

How to validate this kind of json objects.

    {
     "Employee":{
      "name":"Dhruv",
      "code":"emp123",
      "designation":"Accountant",
      "departments":[{}]
      }
    }

Employee DTO:

public class Employee {
  private String name;
  private String code;
  private String designation;
  private List<Department> departments;
}

public class Department{
  private String deptName;
  private string deptCode;
}
2

1 Answer 1

0

The size will be shown as 1 as there is an empty object within the json (Your json is unaware of the model that created it). The only way to check will be,

const hasDepartments = Employee.departments 
    && Employee.departments.length 
    && Employee.departments[0].deptCode;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.