Skip to content

NPE from SqlDateSerializer as _useTimestamp is not check for beeing null #774

@mrowkow

Description

@mrowkow

During serialization I've got the following error:

Caused by: java.lang.NullPointerException
        at com.fasterxml.jackson.databind.ser.std.SqlDateSerializer.serialize(SqlDateSerializer.java:48) [jackson-databind-2.5.2.jar:2.5.2]
        at com.fasterxml.jackson.databind.ser.std.SqlDateSerializer.serialize(SqlDateSerializer.java:18) [jackson-databind-2.5.2.jar:2.5.2]

It is thrown from the method:

public void serialize(java.sql.Date value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonGenerationException
    {
        if (_useTimestamp) {
            jgen.writeNumber(_timestamp(value));
        } else {
            jgen.writeString(value.toString());
        }
    }

because the _useTimestamp is null

It set in DateTimeSerializerBase#createContextual by the framgment (asNumber is null):

                Boolean asNumber = (format.getShape() == JsonFormat.Shape.STRING) ? Boolean.FALSE : null;
                // If not, do we have a pattern?
                TimeZone tz = format.getTimeZone();
                if (format.hasPattern()) {
                    String pattern = format.getPattern();
                    final Locale loc = format.hasLocale() ? format.getLocale() : prov.getLocale();
                    SimpleDateFormat df = new SimpleDateFormat(pattern, loc);
                    if (tz == null) {
                        tz = prov.getTimeZone();
                    }
                    df.setTimeZone(tz);
                    return withFormat(asNumber, df);
                }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions