@MapstructExpression: Usage of quote char (") in expression not possible

Author: OmarHawkCreated Jan 19, 2024Updated Sep 11, 2026
Labelsarea: bug :bug:theme: JDL
Overview of the issue

Hi,

we are using @MapstructExpression to generate some combined field values and want to use some easy String concatenation in the expression so that the final expression from an entity like this:

entity StreamRights {
  name String
  description TextBlob
  @MapstructExpression("java(s.getId() + \" | \" + s.getName())")
  details String
}

looks like this:

    @Mapping(
        target = "details",
        expression = "java(s.getId() + \" | \" + s.getName())"
    )
    StreamRightsDTO toDto(StreamRights s);

Unfortunately, this won't work. It will produce following kind of error when running the jdl command:

Welcome to JHipster v8.1.0

INFO! Generating jdls .\jhipster-jdl.jdl
ERROR! An error occured while running jhipster:jdl#parseJDL
ERROR! ERROR! unexpected character: ->|<- at offset: 3385, skipped 1 characters.
Error: unexpected character: ->|<- at offset: 3385, skipped 1 characters.
    at getCst (file:///C:/Users/jwedding/AppData/Roaming/nvm/v18.19.0/node_modules/generator-jhipster/dist/jdl/parsing/api.js:38:15)
    at Module.parse (file:///C:/Users/jwedding/AppData/Roaming/nvm/v18.19.0/node_modules/generator-jhipster/dist/jdl/parsing/api.js:31:17)
    at callApiMethod (file:///C:/Users/jwedding/AppData/Roaming/nvm/v18.19.0/node_modules/generator-jhipster/dist/jdl/readers/jdl-reader.js:80:34)
    at parse (file:///C:/Users/jwedding/AppData/Roaming/nvm/v18.19.0/node_modules/generator-jhipster/dist/jdl/readers/jdl-reader.js:68:27)
    at Module.parseFromContent (file:///C:/Users/jwedding/AppData/Roaming/nvm/v18.19.0/node_modules/generator-jhipster/dist/jdl/readers/jdl-reader.js:44:12)
    at createImporterFromContent (file:///C:/Users/jwedding/AppData/Roaming/nvm/v18.19.0/node_modules/generator-jhipster/dist/jdl/jdl-importer.js:77:31)
    at JdlGenerator.parseJDL (file:///C:/Users/jwedding/AppData/Roaming/nvm/v18.19.0/node_modules/generator-jhipster/dist/generators/jdl/generator.mjs:130:34)
    at JdlGenerator.executeTask (file:///C:/Users/jwedding/AppData/Roaming/nvm/v18.19.0/node_modules/generator-jhipster/node_modules/yeoman-generator/dist/actions/lifecycle.js:244:26)
    at env.queueTask.once (file:///C:/Users/jwedding/AppData/Roaming/nvm/v18.19.0/node_modules/generator-jhipster/node_modules/yeoman-generator/dist/actions/lifecycle.js:218:56)
    at runLoop.add.once (file:///C:/Users/jwedding/AppData/Roaming/nvm/v18.19.0/node_modules/generator-jhipster/node_modules/yeoman-environment/dist/environment-base.js:384:23)
    at Immediate.<anonymous> (C:\Users\jwedding\AppData\Roaming\nvm\v18.19.0\node_modules\generator-jhipster\node_modules\grouped-queue\lib\subqueue.js:48:34)
    at process.processImmediate (node:internal/timers:476:21)

We also tried more escaping characters (triple \) but that won't work either.

Motivation for or Use Case

The only woraround for us at the moment to avoid using the " char is wrapping each character of the quoted String like this:

Character.toString('|')

and that becomes quite easily really messy...

Reproduce the error
  1. Have a jdl with @MapstructExpression which includes the " character.
  2. Run the jhipster jdl command
  3. Error
Related issues

Nothing found.

Suggest a Fix
JHipster Version(s)

8.1.0

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file

{
  "generator-jhipster": {
    "additionalSubGenerators": "",
    "applicationType": "monolith",
    "authenticationType": "oauth2",
    "baseName": "dataview",
    "buildTool": "maven",
    "cacheProvider": "no",
    "cli": null,
    "clientFramework": "angular",
    "clientPackageManager": "npm",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "creationTimestamp": 1639736978010,
    "databaseType": "sql",
    "devDatabaseType": "mysql",
    "devServerPort": 4200,
    "dtoSuffix": "DTO",
    "enableGradleEnterprise": false,
    "enableHibernateCache": false,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "entities": [
      "StreamRights"
    ],
    "entitySuffix": "",
    "generators": {},
    "incrementalChangelog": true,
    "jhiPrefix": "jhi",
    "jhipsterVersion": "8.1.0",
    "languages": [
      "de",
      "en"
    ],
    "lastLiquibaseTimestamp": 1699892144000,
    "localBlueprint": true,
    "messageBroker": false,
    "nativeLanguage": "de",
    "otherModules": [],
    "packageName": "de.mt.dataview",
    "pages": [],
    "prodDatabaseType": "mysql",
    "reactive": false,
    "sampleWritten": true,
    "searchEngine": "elasticsearch",
    "serverPort": "8180",
    "serverSideOptions": [
      "searchEngine:elasticsearch"
    ],
    "serviceDiscoveryType": "no",
    "skipCheckLengthOfIdentifier": false,
    "skipClient": false,
    "skipFakeData": false,
    "skipUserManagement": true,
    "subGenerators": [],
    "syncUserWithIdp": true,
    "testFrameworks": [],
    "websocket": false,
    "withAdminUi": true
  }
}
Environment and Tools

openjdk version "17.0.7" 2023-04-18 LTS OpenJDK Runtime Environment (Red_Hat-17.0.7.0+7-1) (build 17.0.7+7-LTS) OpenJDK 64-Bit Server VM (Red_Hat-17.0.7.0+7-1) (build 17.0.7+7-LTS, mixed mode, sharing)

git version 2.43.0.windows.1

node: v18.19.0 npm: 10.2.3

Docker version 24.0.2-rd, build e63f5fa

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions

@ChangelogDate("20230512073130")
entity StreamRights {
  name String
  description TextBlob
  @MapstructExpression("java(s.getId() + \" | \" + s.getName())")
  details String
}

dto StreamRights with mapstruct
paginate StreamRights with pagination        
service StreamRights with serviceImpl        
search StreamRights with elasticsearch       
filter StreamRights

The runnable JDL above uses the same single quote escapes as the overview example. The original overescaped attempt is preserved here for reference (diagnostic only):

jdl
  @MapstructExpression("java(s.getId() + \\" | \\" + s.getName())")
Browsers and Operating System
  • Checking this box is mandatory (this is just to show you read everything)

Source: jhipster/generator-jhipster