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

Issue to deserialize string to java util TimeZone #215

Closed
harishajdarevic opened this issue Apr 21, 2021 · 6 comments
Closed

Issue to deserialize string to java util TimeZone #215

harishajdarevic opened this issue Apr 21, 2021 · 6 comments
Milestone

Comments

@harishajdarevic
Copy link

I'm having issues making Jackson object mapper deserialize JSON into an object that has a TimeZone field.

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of com.fasterxml.jackson.module.mrbean.generated.java.util.TimeZone(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('America/New_York')

Any idea is more than welcome.

Thanks

@kupci
Copy link
Member

kupci commented Apr 21, 2021

And this is using the Java 8 module? Reviewing the unit tests might give some idea, and beyond that if you have a code sample showing how the error is arrived at, that would be helpful.

@harishajdarevic
Copy link
Author

harishajdarevic commented Apr 22, 2021

Hi @kupci

Here are is the list of registered modules that is return by objectMapper.findAndRegisterModules()

0 = "com.fasterxml.jackson.datatype.jdk8.Jdk8Module"
1 = "com.fasterxml.jackson.datatype.jsr310.JavaTimeModule"
2 = "com.fasterxml.jackson.datatype.joda.JodaModule"
3 = "com.fasterxml.jackson.module.kotlin.KotlinModule"
4 = "com.hidden.hidden.init.ObjectMapperFactory$1"
5 = "com.fasterxml.jackson.module.mrbean.MrBeanModule"
6 = "com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule"
7 = "com.fasterxml.jackson.datatype.jsr310.JSR310Module"
8 = "com.fasterxml.jackson.module.paramnames.ParameterNamesModule"
9 = "com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module"

And sure that I've code here it is:

objectMapper.readValue(emailMember.getEmailJson(), EmailRequest.class)

where emailMember.getEmailJson() is

{"toAddresses":[{"memberId":1142783,"sponsorId":57947,"emailAddress":"QA5e633008-8d29-4a84-b3c6-fea0c5ef1ca9@QAautovp.com","firstName":"TestFirst8ef1acbc-d11f-4a66-b151-0efdad51c905","lastName":"TestLastbc171f54-50e2-43c7-9640-d5116cdad11c","timeZone":"America/New_York"}],"fromAddress":{"name":"qa-xxxx Pulse","email":"qa-no-reply@xxxx.com","nameWithEmail":"qa-xxxx Pulse <qa-no-reply@xxxx.com>"},"replyToAddress":{"name":"qa-xxxx Pulse","email":"qa-no-reply@xxxx.com","nameWithEmail":"qa-xxxx Pulse <qa-no-reply@xxxx.com>"},"emailId":"bcebda9c-ff7f-4874-a443-755c4549c187","substitutions":{"trackerChallengeEndDate":"Feb 08","whyItMattersSection":"Because it matters...","sponsorName":"paniniTestSponsor","daysToTrack":6,"chatEnabled":true,"tipsSection":"tips and advices...","targetDays":5,"trackerName":"Diabetes Tracker","contentPhotoUrl":"https://file.xxxx.com/api/file/j4pbqUsJTQKQvnDIGjqB","totalDays":5,"sponsorLogoUrl":"https://miro.medium.com/max/1200/1*HSrZUaWEY4psyxup9auZUw.jpeg","checkTheYesOMeterUrl":"https://aa.xxxx.com/?email=QA5e633008-8d29-4a84-b3c6-fea0c5ef1ca9%40QAautovp.com#/challenges/healthyhabits/34901","joinTheChallengeUrl":"https://aa.xxxx.com/?email=QA5e633008-8d29-4a84-b3c6-fea0c5ef1ca9%40QAautovp.com#/challenges/healthyhabits/34901","seventhDay":"Feb 08","trackerChallengeStartDate":"Feb 04"},"emailType":"PromotedTrackerChallengeInvitation","locale":"en_us","content":"","subject":"","data":"","sendDateTime":"2021-04-21T15:00:00","emailDeliveryType":"Promotional","resend":false,"batchId":"PromotedTrackerChallengeId-22013-sponsorId-57947-batch-2","emailRequestType":"MemberEmail"}

and EmailRequest.class

public final data class EmailRequest public constructor(toAddresses: kotlin.collections.Set<com.xxx.notifications.sdk.representations.email.Member> /* = compiled code */, fromAddress: com.xxx.notifications.sdk.representations.email.Addressee, replyToAddress: com.xxx.notifications.sdk.representations.email.Addressee /* = compiled code */, emailId: java.util.UUID /* = compiled code */, substitutions: kotlin.collections.Map<kotlin.String, kotlin.Any> /* = compiled code */, emailType: kotlin.String /* = compiled code */, locale: com.xxx.notifications.sdk.representations.Language, content: kotlin.String /* = compiled code */, subject: kotlin.String /* = compiled code */, data: kotlin.String /* = compiled code */, templateId: kotlin.String? /* = compiled code */, sendDateTime: java.time.LocalDateTime? /* = compiled code */, emailDeliveryType: com.xxx.notifications.sdk.representations.email.EmailDeliveryType /* = compiled code */, resend: kotlin.Boolean /* = compiled code */, batchId: kotlin.String? /* = compiled code */, emailRequestType: com.xxx.notifications.sdk.representations.email.EmailRequestType /* = compiled code */) : com.xxx.notifications.sdk.service.JsonSerializable {
    public final val batchId: kotlin.String? /* compiled code */

    public final val content: kotlin.String /* compiled code */

    public final val data: kotlin.String /* compiled code */

    public final val emailDeliveryType: com.xxx.notifications.sdk.representations.email.EmailDeliveryType /* compiled code */

    public final val emailId: java.util.UUID /* compiled code */

    public final val emailRequestType: com.xxx.notifications.sdk.representations.email.EmailRequestType /* compiled code */

    @field:com.xxx.notifications.sdk.validators.NotBlank public final val emailType: kotlin.String /* compiled code */

    public final val fromAddress: com.xxx.notifications.sdk.representations.email.Addressee /* compiled code */

    public final val locale: com.xxx.notifications.sdk.representations.Language /* compiled code */

    public final val replyToAddress: com.xxx.notifications.sdk.representations.email.Addressee /* compiled code */

    public final val resend: kotlin.Boolean /* compiled code */

    public final val sendDateTime: java.time.LocalDateTime? /* compiled code */

    public final val subject: kotlin.String /* compiled code */

    public final val substitutions: kotlin.collections.Map<kotlin.String, kotlin.Any> /* compiled code */

    public final val templateId: kotlin.String? /* compiled code */

    public final val toAddresses: kotlin.collections.Set<com.xxx.notifications.sdk.representations.email.Member> /* compiled code */

Member class that contain timeZone

public final data class Member public constructor(memberId: kotlin.Long? /* = compiled code */, employeeId: kotlin.String? /* = compiled code */, sponsorId: kotlin.Long, emailAddress: kotlin.String, firstName: kotlin.String?, lastName: kotlin.String?, timeZone: java.util.TimeZone) : com.xxx.notifications.sdk.service.JsonSerializable {
@field:com.xxx.notifications.sdk.validators.Email public final val emailAddress: kotlin.String /* compiled code */

public final val employeeId: kotlin.String? /* compiled code */

public final val firstName: kotlin.String? /* compiled code */

public final val lastName: kotlin.String? /* compiled code */

public final val memberId: kotlin.Long? /* compiled code */

public final val sponsorId: kotlin.Long /* compiled code */

@field:com.xxx.notifications.sdk.validators.NotBlank public final val timeZone: java.util.TimeZone /* compiled code */

@harishajdarevic
Copy link
Author

I found it.

I've to register a new instance of objectMapper without MrBean module. There is conflict with it that is culprit for above error.

@kupci
Copy link
Member

kupci commented Apr 23, 2021

There do seem to be some caveats mentioned on the Mr. Bean documentation that might explain this. Anyway, glad you found the conflict.

@cowtowncoder
Copy link
Member

If there was an easy way to reproduce this, we could try to see if something could be done to prevent this specific issue.
In general it is a difficult problem -- MrBean does materialize interfaces, abstract classes, and cannot know what all modules might produce -- but at least I could verify that this can be problematic, and if so, can it be avoided by java8 module.

Or, actually, MrBean: I suspect it should never try to materialize anything under "java." or "javax.". And adding such setting (behind a config feature) seems simple enough.

@cowtowncoder
Copy link
Member

I created an issue for Mr Bean; and fixed it -- java.util.TimeZone should work as expected in 2.12.4 / 2.13.0; 2.13.0 will by default prevent materialization of anything under java.* (unless we find some big issues with that exclusion).

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

3 participants