Add customization option for LocalDateTime handling of seconds and nanos
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia da datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/LocalDateTimeSerializer.java, in particolare da _serializeAsArrayContents intorno alla riga 112, e segui come vengono configurate le opzioni di serializzazione di LocalDateTime. Il lavoro è completato quando gli utenti possono scegliere di emettere secondi e nanos quando sono zero, senza dover usare un serializer o un mapper personalizzato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi all,
as seen in https://github.com/FasterXML/jackson-modules-java8/blob/master/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/LocalDateTimeSerializer.java method _serializeAsArrayContents line 112, if seconds or nanos are set to 0 in the LocalDateTime object being serialized, they will NOT be included into the resulting JSON.
I understand this might be trying to follow what its toString https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html#toString does, but it is not convenient when senders and receivers either do not understand the LocalDateTime specification or are unable to handle it properly.
Please add a customization option to allow sending seconds and nanos even when set to 0, the only current workaround is to implement a custom serializer and add it to a custom mapper to be passed in whatever configuration needs it, which is not really convenient:
public static class LocalDateTimeWithSecondsSerializer extends StdSerializer<LocalDateTime> {
public LocalDateTimeWithSecondsSerializer() {
super(LocalDateTime.class);
}
@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeStartArray();
gen.writeNumber(value.getYear());
gen.writeNumber(value.getMonthValue());
gen.writeNumber(value.getDayOfMonth());
gen.writeNumber(value.getHour());
gen.writeNumber(value.getMinute());
gen.writeNumber(value.getSecond());
gen.writeEndArray();
}
}
public static class CustomEntityMapper implements EntityMapper {
private final ObjectMapper objectMapper;
public CustomEntityMapper() {
SimpleModule localDateTimeWithSecondsSerializerModule = new SimpleModule();
localDateTimeWithSecondsSerializerModule.addSerializer(new LocalDateTimeWithSecondsSerializer());
objectMapper = new ObjectMapper()
.registerModule(new JavaTimeModule())
.registerModule(localDateTimeWithSecondsSerializerModule)
.registerModule(new Jdk8Module());
objectMapper.findAndRegisterModules();
}
@Override
public String mapToString(Object object) throws IOException {
return objectMapper.writeValueAsString(object);
}
@Override
public <T> T mapToObject(String source, Class<T> clazz) throws IOException {
return objectMapper.readValue(source, clazz);
}
}
Thanks and cheers
- Lingua principale
- Java
- Stelle
- 425
- Fork
- 125
- Merge medio
- 19m
- PR unite (30g)
- 1
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di FasterXML/jackson-modules-java8
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
-
Wrap `DateTimeException` Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
FasterXML/jackson-modules-java8#382 · 3 commenti ·
-
date-time-config
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
FasterXML/jackson-modules-java8#374 · 31 commenti · 1 reazione ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
FasterXML/jackson-modules-java8#310 · 1 commento ·
-
Instants get not deserialized as expected sometimes (millis vs nanos, non-fractional numbers) Apertatest-needed
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
FasterXML/jackson-modules-java8#304 · 3 commenti ·
Tutte le issue di FasterXML/jackson-modules-java8
Issue simili
-
executions.Query — startDate and timeRange filters are sent with inverted comparison operators Apertaarea/plugin
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
kestra-io/plugin-kestra#190 ·
-
litertlm-android AAR ships no consumer ProGuard rules → "mid == null" SIGABRT in minified apps Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
integra-team-red/meet-map#249 ·
-
[Studio][Bug] Cancelled create-user dialog keeps the password and admin switch for the next attempt Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
apache/rocketmq-dashboard#5064 ·