tech.deepdreams.employee.deserializers.ContractStartedEventDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of employee-events Show documentation
Show all versions of employee-events Show documentation
HR employee events project for Spring Boot
The newest version!
package tech.deepdreams.employee.deserializers;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import tech.deepdreams.employee.enums.ContractType;
import tech.deepdreams.employee.events.ContractStartedEvent;
public class ContractStartedEventDeserializer extends JsonDeserializer{
@Override
public ContractStartedEvent deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
Long id = jsonNode.get("id").asLong();
Long employeeId = jsonNode.get("employeeId").asLong();
OffsetDateTime eventDate = OffsetDateTime.parse(jsonNode.get("eventDate").asText(), DateTimeFormatter.ISO_DATE_TIME) ;
LocalDate hiringDate = LocalDate.parse(jsonNode.get("hiringDate").asText()) ;
ContractType contractType = ContractType.valueOf(jsonNode.get("contractType").asText()) ;
Integer contractDuration = jsonNode.get("contractDuration") == null ? null : jsonNode.get("contractDuration").asInt();
BigDecimal baseSalary = BigDecimal.valueOf(jsonNode.get("baseSalary").asDouble()) ;
Double weeklyWorkingHours = jsonNode.get("weeklyWorkingHours").asDouble() ;
Integer annualLeaveDays = jsonNode.get("annualLeaveDays").asInt() ;
Integer retirementAge = jsonNode.get("retirementAge").asInt() ;
Long unitId = jsonNode.get("unitId") == null ? null : jsonNode.get("unitId").asLong() ;
Long functionId = jsonNode.get("functionId") == null ? null : jsonNode.get("functionId").asLong() ;
Long categoryId = jsonNode.get("categoryId") == null ? null : jsonNode.get("categoryId").asLong() ;
Long echelonId = jsonNode.get("echelonId") == null ? null : jsonNode.get("echelonId").asLong() ;
String username = jsonNode.get("username").asText() ;
return ContractStartedEvent.builder()
.id(id)
.employeeId(employeeId)
.eventDate(eventDate)
.hiringDate(hiringDate)
.contractType(contractType)
.contractDuration(contractDuration)
.baseSalary(baseSalary)
.weeklyWorkingHours(weeklyWorkingHours)
.annualLeaveDays(annualLeaveDays)
.retirementAge(retirementAge)
.unitId(unitId)
.functionId(functionId)
.categoryId(categoryId)
.echelonId(echelonId)
.username(username)
.build() ;
}
}