fix: JsonHelper LocalDateTime serialization and compact logging
This commit is contained in:
parent
3398e12c72
commit
40189e4a9c
@ -21,8 +21,20 @@ public class JsonHelper {
|
||||
static {
|
||||
MAPPER.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
MAPPER.registerModule(new JavaTimeModule());
|
||||
MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
|
||||
// Intentar registrar módulos automáticamente (incluye JavaTimeModule si está disponible)
|
||||
try {
|
||||
MAPPER.findAndRegisterModules();
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Error auto-registering Jackson modules, trying manual registration: {0}", e.getMessage());
|
||||
// Fallback: intentar registro manual del JavaTimeModule
|
||||
try {
|
||||
MAPPER.registerModule(new JavaTimeModule());
|
||||
} catch (Exception e2) {
|
||||
logger.log(Level.SEVERE, "Error registering JavaTimeModule: {0}", e2.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,6 +55,25 @@ public class JsonHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Object to jsonString in compact format (single line, includes nulls)
|
||||
*
|
||||
* @param object El objeto a convertir en JSON.
|
||||
* @return La cadena JSON compacta en una sola línea o null si ocurre un error.
|
||||
*/
|
||||
public static String getJsonFromObjectExcludingNulls(Object object) {
|
||||
if (object == null) {
|
||||
return "null";
|
||||
}
|
||||
try {
|
||||
// Usar el formato compacto (sin pretty print) pero manteniendo todos los campos incluyendo nulls
|
||||
return MAPPER.writeValueAsString(object);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.log(Level.SEVERE, "Error parsing objeto a JSON: {0}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convierte una cadena JSON en un objeto Java de la clase especificada.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user