Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
Formato no válido para createdBy en SpringBoot Auditable

Implementé SpringBoot Auditable y todo funciona bien, excepto que createdBy proporciona una marca de tiempo.

Aquí está mi clase auditable:

 @Getter @Setter public class Auditable { @CreatedDate private LocalDateTime createdAt; @LastModifiedDate private LocalDateTime updatedAt; @CreatedBy private ObjectId createdBy; @LastModifiedBy private ObjectId updatedBy; }

Y aquí está mi clase AuditorAwareImpl:

 public class AuditorAwareImpl implements AuditorAware<ObjectId> { @Override public Optional<ObjectId> getCurrentAuditor() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); ObjectId userId = null; if (authentication != null) { UserDetails userDetails = (UserDetails) authentication.getPrincipal(); userId = new ObjectId(userDetails.getId()); } return Optional.of(userId); } }

Está (ObjectId) guardando bien en DB. Pero cuando recupero ese registro, me crean con un formato diferente en lugar de ObjectId:

ingrese la descripción de la imagen aquí

Alguien me puede ayudar con esto por favor?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Simplemente agregue este bean y convierta el ObjectId en String.

Dependencia

 <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.11.0.rc1</version> </dependency>

Y agrega el frijol

 @SpringBootApplication public class DivisionServiceApplication { public static void main(String[] args) { SpringApplication.run(DivisionServiceApplication.class, args); } @Bean public Jackson2ObjectMapperBuilderCustomizer customizer() { return builder -> builder.serializerByType(ObjectId.class, new ToStringSerializer()); } }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda