tech.deepdreams.security.deserializers.UserSuspendedEventDeserializer Maven / Gradle / Ivy
package tech.deepdreams.security.deserializers;
import java.io.IOException;
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.security.events.UserSuspendedEvent;
public class UserSuspendedEventDeserializer extends JsonDeserializer{
@Override
public UserSuspendedEvent deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
Long id = jsonNode.get("id").asLong();
String nickname = jsonNode.get("nickname").asText() ;
String email = jsonNode.get("email").asText() ;
OffsetDateTime eventDate = OffsetDateTime.parse(jsonNode.get("eventDate").asText(), DateTimeFormatter.ISO_DATE_TIME) ;
String description = jsonNode.get("description").asText() ;
Integer duration = Integer.parseInt(jsonNode.get("duration").asText()) ;
Long subscriberId = jsonNode.get("subscriberId").asLong();
return UserSuspendedEvent.builder()
.id(id)
.nickname(nickname)
.email(email)
.eventDate(eventDate)
.duration(duration)
.description(description)
.subscriberId(subscriberId)
.build() ;
}
}