1
Exception Message: org.modelmapper.MappingException: ModelMapper mapping errors:1) Error mapping
  at org.modelmapper.internal.Errors.throwMappingExceptionIfErrorsExist(Errors.java:380)
  at org.modelmapper.internal.MappingEngineImpl.map(MappingEngineImpl.java:81)
  at org.modelmapper.ModelMapper.mapInternal(ModelMapper.java:573)
  at org.modelmapper.ModelMapper.map(ModelMapper.java:406)
  at rest.translator.impl.MongoDbDocumentTranslatorImpl.toResponse(MongoDbDocumentTranslatorImpl.java:214)
  at rest.translator.impl.MongoDbDocumentTranslatorImpl.translate(MongoDbDocumentTranslatorImpl.java:200)
  at rest.translator.impl.UserInformationTranslatorImpl.translate(UserInformationTranslatorImpl.java:38)
  at rest.controller.UserController.lambda$getAll$1(UserController.java:106)
  at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
  at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
  at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)...

I tried updating the model mapper plugin.It does not work.

In Local, the getAll endpoint seems to be working.
At environment server level, fails with a model mapper exception.

These are the following dependencies:

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-actuator'
    compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
    compile 'org.springframework.boot:spring-boot-starter-security'
    compile 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.0.M4'
    compile 'org.springframework.boot:spring-boot-starter-log4j2'
    compile 'org.springframework.security:spring-security-oauth2-resource-server'
    compile 'org.springframework.security:spring-security-oauth2-jose'
    compile 'org.springframework.security:spring-security-config'
    compile 'org.springframework.retry:spring-retry'
    compile 'org.springframework.boot:spring-boot-starter-cache'
    compile 'org.springframework.boot:spring-boot-starter-data-redis'
    compile('org.springframework.boot:spring-boot-starter-web') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    compile 'io.micrometer:micrometer-registry-prometheus'

    compile 'com.nimbusds:oauth2-oidc-sdk:7.1.1'

    compile 'io.springfox:springfox-swagger2:2.9.2'
    compile 'io.springfox:springfox-swagger-ui:2.9.2'
    compile 'io.springfox:springfox-bean-validators:2.9.2'
    compile "gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.22.1"
    compile "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8"
    compile 'org.apache.commons:commons-lang3:3.0'
    compile 'commons-io:commons-io:2.6'
    compile 'org.aspectj:aspectjweaver'
    compile 'org.modelmapper:modelmapper:2.3.9'
    compile 'com.amazonaws:aws-java-sdk-s3:1.11.797'
    compile 'com.amazonaws:aws-java-sdk-core:1.11.797'
    compile 'org.assertj:assertj-core:3.6.2'
    runtime 'org.springframework.boot:spring-boot-starter-tomcat'
    testCompile 'org.springframework.boot:spring-boot-starter-test'
    testCompile 'org.springframework.security:spring-security-test'
    testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc'
    testCompile 'de.bwaldvogel:mongo-java-server:1.16.0'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
    testCompile group: 'io.findify', name: 's3mock_2.12', version: '0.2.6'
    compile 'io.cucumber:cucumber-java:4.5.3'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '2.4.2'
    compileOnly "org.springframework.boot:spring-boot-configuration-processor"
    // jdk 11 migration dependencies
    implementation "javax.xml.bind:jaxb-api:2.3.1"
    implementation "com.sun.xml.bind:jaxb-core:2.3.0.1"
    implementation "com.sun.xml.bind:jaxb-impl:2.3.1"
    implementation "com.sun.activation:javax.activation:1.2.0"
    implementation("javax.annotation:javax.annotation-api:1.3.2")
    compile group: 'org.ow2.asm', name: 'asm', version: '7.1'
    testCompile("javax.xml.ws:jaxws-api:2.3.1")
    implementation 'org.springframework.boot:spring-boot-test'
    implementation 'org.springframework.boot:spring-boot-test-autoconfigure'
    // end of jdk 11 migration dependencies
}

modelmapper 2.4.0 also results in same exception.

What is the possible fix!!?

  • did you check all the dependencies? – MoKi Apr 11 '23 at 13:05
  • All dependencies have been updated – hemanth reddy m Apr 11 '23 at 13:08
  • 2
    If it works locally, but fails at the server level, I suggest you take a look at your active JDK on the server level. There must be a difference between your local setup vs server. – JCompetence Apr 11 '23 at 13:14
  • JDK on server is also jdk11 $ java -version openjdk version "11.0.7" 2020-04-14 LTS OpenJDK Runtime Environment Zulu11.39+15-CA (build 11.0.7+10-LTS) OpenJDK 64-Bit Server VM Zulu11.39+15-CA (build 11.0.7+10-LTS, mixed mode) – hemanth reddy m Apr 11 '23 at 13:44
  • 1
    Suggest reading, all answers here and comments as well, https://stackoverflow.com/questions/37916165/spring-modelmapper-error-mapping-already-exists-for-controller, Also Check if null check helps as mentioned – Naseer Mohammad Apr 11 '23 at 14:25
  • Also your question says errors exist, But what are the errors that are causing exception?, could you post the full stack trace, If that shows!! – Naseer Mohammad Apr 11 '23 at 14:43

1 Answers1

0

The error was resolved by upgrading the version of the org.springframework.boot dependency from 2.2.4.RELEASE to 2.2.11.RELEASE, which also updated the version of the spring.data.mongodb.core dependency.

This update fixed the issue with model mapping, which was caused by the previous version of the spring.data.mongodb.core dependency.

Andreas Violaris
  • 2,465
  • 5
  • 13
  • 26