All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.deepdreams.employee.deserializers.ContractRenewedEventDeserializer 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 ContractRenewedEventDeserializer 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() ;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy