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

ModelMapper sometimes maps null values into fields randomly #580

Open
vvedharaju opened this issue Feb 6, 2021 · 7 comments
Open

ModelMapper sometimes maps null values into fields randomly #580

vvedharaju opened this issue Feb 6, 2021 · 7 comments

Comments

@vvedharaju
Copy link

vvedharaju commented Feb 6, 2021

Here is our model mapper configuration in our Spring Boot app. We use this integrated with jooq and we use the same mapper for non-jooq mappings as well.

@Bean
    public ModelMapper modelMapper() {
        ModelMapper mapper = new ModelMapper();
        mapper
                .getConfiguration()
                .addValueReader(new RecordValueReader())
                .setSourceNameTokenizer(NameTokenizers.UNDERSCORE)
                .setSkipNullEnabled(true)
                .setPropertyCondition(Conditions.isNotNull());
        mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        return mapper;
    }

We added the following logs:

System.out.println("debugLandingPage > Model Mapper"+eventLandingPage);
EventLandingPageViewDTO eventLandingPageViewDTO =  mapper.map(eventLandingPage, EventLandingPageViewDTO.class);
System.out.println("debugLandingPage > After Map Model Mapper"+eventLandingPageViewDTO);

and we got the following output:

Feb 6 17:14:31 ip-172-31-45-191 backend.log debugLandingPage > Model MapperEventLandingPage (7b97df87-d1e7-452d-a679-83dd13bdaa41, 756dfa3b-5a31-4ca1-a817-bbed8f7e2986, BASIC, https://phoenixlive.imgix.net///412ac2ac-e162-4627-aa49-44b58960fa8d.jpg, https://zuddl.imgix.net///b4d0aba3-39ae-4b89-b6f3-8f61e819c621.png, https://zuddl.imgix.net//3bd69d2f-8e06-4355-9972-10bb48a43746.png, true, EMAIL, #ec1d25, #DDDDDD, null, null, null, null, 2021-02-06T11:14:42.656562Z, 2021-02-06T11:14:42.656562Z)
Feb 6 17:14:31 ip-172-31-45-191 backend.log debugLandingPage > After Map Model MapperEventLandingPageViewDTO(eventLandingPageId=null, eventId=null, landingPageTemplateName=null, backgroundImageUrl=null, logoImageUrl=null, logoImageUrlTwo=null, isCountDownRequired=null, registrationCheckInType=null, formBgColour=null, formFontColour=null, isDisclaimerRequired=null, isPromptRequired=null, disclaimerMessage=null, promptMessage=null, eventLandingPageSponsorDTOList=null, eventCustomFieldKeyList=null)

Everything is somehow mapped to null. This happens pretty inconsistently and sometimes gets fixed just by rerunning the app. We're not really sure what's happening.

@awaisazeem
Copy link

I am facing the similar issue , issue gets fixed after i rerun the spring boot app 2.4.1 with java 8. i am using model mapper version 2.3.7. The issue is pretty inconsistent.

@chhsiao90
Copy link
Member

Can you provide the reproducible code or model definitions? Thanks!

@surajray123
Copy link

@awaisazeem were you able to fix this?

@saintjab
Copy link

Any solution with this? I am facing similar issue

@WatchdataGitHub
Copy link

WatchdataGitHub commented Sep 13, 2022 via email

@flash548
Copy link

flash548 commented Mar 2, 2023

Same here - Spring Boot 2.5.14, ModelMapper 2.4.4, openjdk 11.0.18

Trying to post a reproducible, consistent case is nearly impossible. I know that doesn't help anything...

But seems to be when mapping from a DTO (just an uuid for instance) to a Db Model - where the final output is expected to be a Db entity object with its nested/populated subobjects pointed to by the UUIDs in the DTO.... works 99% of the time. That 1% of the time, those would-be nested subobjects are come out of the mapping process as null.

Restarting the app when in this failure mode, fixes the problem almost everytime.

@flash548
Copy link

flash548 commented Mar 8, 2023

Actually this was my doing... we had a Bean for ModelMapper setup in Spring, and there was once place in the code that set config to STRICT thereby tarnishing that instance for the rest of the app's life in STRICT mode. STANDARD works all over now.

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

No branches or pull requests

7 participants