I have timezone POJO as below:
@Entity
public class TimeZoneDto implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "timezone_sequence")
@SequenceGenerator(name = "timezone_sequence", sequenceName = "t_timeZone_master_id_seq", initialValue = 1, allocationSize = 1)
private Long id;
@Column
private String timeZone;
@Column
private String name;
@Column
private double hourDifference;
/* all gettet/setter */
}
I have updateTimeZone method in Spring Controller as below:
@RequestMapping(value = "updateTimezone", consumes = "application/json", produces = "application/json", method = RequestMethod.POST)
public ResponseEntity<Object> updateTimezone(@RequestBody TimeZoneDto timeZoneDto){
}
when I pass request as below:
{"id":14,"name":"America/Los_Angeles -7:00 GMT"}
then it automatically convert other values with default values when map with POJO and it becomes:
id=14, timeZone=null, name=America/Los_Angeles -7:00 GMT, hourDifference=0.0
because of this when I update this POJO as below
getEntityManager().merge(timezoneDto);
it override TimeZone = null and hourDifference = 0.0 automatically,
so is there any way by which my TimeZoneDto in @RequestBody has only those columns which I pass in request JSON.
EDIT
I have used below on Class but its not work
@JsonInclude(value=Include.NON_EMPTY)
OR
@JsonInclude(value=Include.NON_DEFAULT)