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

ObjectMapper.setDefaultLeniency() is causing NullPointerException in JacksonJodaDateFormat #113

Closed
brenuart opened this issue Nov 21, 2019 · 3 comments
Milestone

Comments

@brenuart
Copy link

(Jackson version: 2.10.1)

Consider the following example:

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
mapper.setDefaultLeniency(false);
mapper.writeValueAsString(new org.joda.time.DateTime());

This code raises the following exception:

java.lang.NullPointerException
	at com.fasterxml.jackson.datatype.joda.cfg.JacksonJodaDateFormat.with(JacksonJodaDateFormat.java:123)
	at com.fasterxml.jackson.datatype.joda.ser.JodaDateSerializerBase.createContextual(JodaDateSerializerBase.java:94)
	at com.fasterxml.jackson.databind.SerializerProvider.handleSecondaryContextualization(SerializerProvider.java:1004)
	at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:524)
	at com.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:713)
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:308)
	at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:4094)
	at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3404)
...

This is caused by JsonFormat.Value#getPattern() returning null at line https://github.com/FasterXML/jackson-datatype-joda/blob/master/src/main/java/com/fasterxml/jackson/datatype/joda/cfg/JacksonJodaDateFormat.java#L123.

Note that getPattern returns an empty string when JsonFormat comes from an annotation, but null when created because of ObjectMapper.setDefaultLenciency().

@cowtowncoder
Copy link
Member

Thank you for reporting this. I'll transfer it to Joda module.

@cowtowncoder cowtowncoder transferred this issue from FasterXML/jackson-core Nov 21, 2019
@cowtowncoder cowtowncoder added 2.10 good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project labels Nov 21, 2019
@brenuart
Copy link
Author

brenuart commented Nov 22, 2019

I was wondering if the issue belongs to the joda module or not.
The problem is caused by the JsonFormat.Value containing a null pattern value when created by one of the with*() methods but having an empty string when used as an annotation. If this is normal and expected - then indeed the issue belongs to Joda...

@cowtowncoder
Copy link
Member

@brenuart Ah. Ok, in that case I think I better have a look myself. It is possible change is needed in multiple places. Thank you for additional information!

@cowtowncoder cowtowncoder added 2.11 and removed 2.10 labels Apr 16, 2020
@cowtowncoder cowtowncoder changed the title ObjectMapper.setDefaultLeniency() is causing NullPointerException in JacksonJodaDateFormat ObjectMapper.setDefaultLeniency() is causing NullPointerException in JacksonJodaDateFormat Apr 16, 2020
@cowtowncoder cowtowncoder removed 2.11 good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project labels Apr 16, 2020
@cowtowncoder cowtowncoder added this to the 2.10.4 milestone Apr 16, 2020
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