2

I have a DTO like below

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * Simple DTO for ServiceContract.
 */
public class ServiceContractDTO {
    public Long id;
    public String name;
    public String description;
    public String type;
    public Long contractStart;
    public Long contractEnd;
    public Boolean isrepeated;
    public Boolean autoApproved;
    public Boolean staffAutoApproved;
    public Long createdts;
    public Long updatedts;
    public String createdby;
    public String status;

    public HospitalDTO hospital;
    public HospitalUnitDTO unit;
    public StaffDTO preferredStaff;
    public SpecialtyDTO specialty;
    public SkillMasterDTO skill;

    public ServiceLocationDTO serviceLocation;
    public ServiceScheduleDTO serviceSchedule;

    @JsonIgnore
    public boolean isIdSet() {
        return id != null;
    }
}

Now I get only not null fields from UI if its an update. How do I set only those and update the object. I dont want to check for null for all these properties and set them..Is there a better approach?

I will get a json like

{
        "id": 13,
        "name": "test contract"
}

Any code samples will help

coder310
  • 83
  • 1
  • 1
  • 10
  • 1
    How do you map from the DTO to a JPA entity? – Thomas Kåsene Oct 15 '16 at 07:13
  • Spring MVC does not support PATCH (i.e. partial update). See my answer and associated links here:http://stackoverflow.com/a/39424421/1356423 – Alan Hay Oct 15 '16 at 08:46
  • JPA would only update specific fields if you updated just those fields. No JPA API code posted so likely you are doing something else ... – Neil Stockton Oct 15 '16 at 10:07
  • This DTO is actually mapped to the json that I will be getting from UI. Internally I convert the DTO to entity for persisting in the DB. The reason for posting this DTO is that this are the fields that are expected from the UI. – coder310 Oct 15 '16 at 15:07

0 Answers0