tech.deepdreams.employee.deserializers.ContractExpiredEventDeserializer Maven / Gradle / Ivy
package tech.deepdreams.employee.deserializers;
import java.io.IOException;
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.events.ContractExpiredEvent;
public class ContractExpiredEventDeserializer extends JsonDeserializer{
@Override
public ContractExpiredEvent 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 expirationDate = LocalDate.parse(jsonNode.get("eventDate").asText()) ;
String username = jsonNode.get("username").asText() ;
return ContractExpiredEvent.builder()
.id(id)
.employeeId(employeeId)
.eventDate(eventDate)
.expirationDate(expirationDate)
.username(username)
.build() ;
}
}