Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mrowkow opened this issue Apr 29, 2015 · 2 comments
Closed
Milestone

Comments

@mrowkow
Copy link

mrowkow commented Apr 29, 2015

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);
                }

@cowtowncoder
Copy link
Member

Sounds like a bug indeed, thank you for reporting this.

@cowtowncoder cowtowncoder added this to the 2.5.4 milestone Apr 29, 2015
@cowtowncoder
Copy link
Member

Fixed for 2.5.4 (no more 2.4 releases planned)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants