Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedetta-fabbri committed Jan 16, 2025
1 parent 3d826a2 commit e7b639e
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/main/java/it/gov/pagopa/pu/organization/model/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package it.gov.pagopa.pu.organization.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
Expand All @@ -13,8 +16,11 @@
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.io.IOException;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;

@Data
@SuperBuilder(toBuilder = true)
Expand All @@ -25,11 +31,24 @@
public abstract class BaseEntity implements Serializable {
@Column(updatable = false)
@CreatedDate
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
@JsonSerialize(using = LocalDateTimeToOffsetDateTimeSerializer.class)
private LocalDateTime creationDate;
@LastModifiedDate
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
@JsonSerialize(using = LocalDateTimeToOffsetDateTimeSerializer.class)
private LocalDateTime updateDate;
@LastModifiedBy
private String updateOperatorExternalId;

public static class LocalDateTimeToOffsetDateTimeSerializer extends JsonSerializer<LocalDateTime> {

@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (value != null) {
OffsetDateTime offsetDateTime = value.atOffset(ZoneOffset.UTC);
gen.writeString(offsetDateTime.toString());
}
}
}
}


0 comments on commit e7b639e

Please sign in to comment.