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

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

Open
1 task done
OmarHawk opened this issue Jan 19, 2024 · 1 comment
Open
1 task done

Comments

@OmarHawk
Copy link
Contributor

OmarHawk commented Jan 19, 2024

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

Browsers and Operating System
  • Checking this box is mandatory (this is just to show you read everything)
Copy link
Contributor

github-actions bot commented Jan 19, 2024

JHipster has completed the sample check
.yo-rc.json: valid
Entities JDL: error
Application:
Frontend check: skipped
Backend check: skipped
E2E check: skipped

This check uses jhipster info output from the issue description to generate the sample.
Bug report that does not contain this information will be marked as invalid.

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

Successfully merging a pull request may close this issue.

2 participants