Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

OffsetTimeSerializer not writing seconds for time object like 15:30:00Z (where seconds is 00)

Abierto
#299 4 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
java
Área
api, backend

Línea de trabajo

Comience con datetime/src/main/java/tools/jackson/datatype/jsr310/ser/OffsetTimeSerializer.java, especialmente _serializeAsArrayContents, y reproduzca la serialización de 15:00:00Z con JavaTimeModule. Confirme la representación temporal esperada en JSON y determine si es apropiado el comportamiento solicitado o un hook de serializador sobrescribible; se considera terminado cuando el comportamiento está cubierto por una prueba de regresión.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

pr-welcome test-needed

When having a OffsetTime field with e.g. 15:00:00Z and serializing this with Jackson it outputs:
15:00Z and thus the seconds are lost.

Note I have the time module registered via JavaTimeModule().

Although one could argue that the seconds are not needed this gives some problems when validating outputted data against JSON schema.
when using the JSON schema format time then the seconds are expected, see https://json-schema.org/understanding-json-schema/reference/string#dates-and-times
without the seconds the JSON schema validator fails with: The value must be a valid time.
(note I'm using Justify for schema validation)

Looking at the source code, I see this is done on purpose
https://github.com/FasterXML/jackson-modules-java8/blob/master/datetime/src/main/java/tools/jackson/datatype/jsr310/ser/OffsetTimeSerializer.java#L92-L111

    private final void _serializeAsArrayContents(OffsetTime value, JsonGenerator g,
            SerializerProvider provider)
        throws JacksonException
    {
        g.writeNumber(value.getHour());
        g.writeNumber(value.getMinute());
        final int secs = value.getSecond();
        final int nanos = value.getNano();
        if ((secs > 0) || (nanos > 0)) {
            g.writeNumber(secs);
            if (nanos > 0) {
                if(useNanoseconds(provider)) {
                    g.writeNumber(nanos);
                } else {
                    g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND));
                }
            }
        }
        g.writeString(value.getOffset().toString());
    }

Is it possible to override this behaviour?

Currently I think my only option is create a custom Serializer?

If not possible to override this behaviour would it be at least possible to change this _serializeAsArrayContents method from private to protected so one could simply extend this class and override this method?

Lenguaje dominante
Java
Estrellas
425
Forks
125
Merge medio
19 min
PR fusionados (30 d)
1

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de FasterXML/jackson-modules-java8

Todos los issues de FasterXML/jackson-modules-java8

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.