jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.5k stars 4.02k forks source link

In React, a numeric field of an entity is sent as a string in the JSON via REST API. #23763

Closed hide212131 closed 11 months ago

hide212131 commented 1 year ago
Overview of the issue

I'll provide an example below. salary represents the numeric field.

When newly inputted, the field is sent as a string.

field_new

When updated without any changes, the field is sent as a number.

feild_update_nothing

When updated with changes, the field is sent as a string.

field_update
Motivation for or Use Case

While this doesn't directly cause an error, it can lead to confusion during frontend development that adheres to API specifications.

Reproduce the error

Perform registration and update operations on numeric fields.

Related issues
Suggest a Fix

The following processing should be performed on numeric fields.

{entityname}-update.tsx:

  const saveEntity = values => {
    values.salary = values.salary ? parseInt(values.salary, 10) : values.salary;
JHipster Version(s)

8.0.0-beta.3

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "myApp",
    "buildTool": "maven",
    "cacheProvider": "ehcache",
    "clientFramework": "react",
    "clientTestFrameworks": [],
    "clientTheme": "none",
    "creationTimestamp": 1696591837279,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "devServerPort": 9060,
    "enableGradleEnterprise": null,
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "entities": [
      "Employee"
    ],
    "gradleEnterpriseHost": null,
    "jhipsterVersion": "8.0.0-beta.3",
    "languages": [
      "ja",
      "en",
      "fr"
    ],
    "lastLiquibaseTimestamp": 1696591897000,
    "messageBroker": false,
    "microfrontend": null,
    "microfrontends": [],
    "nativeLanguage": "ja",
    "packageName": "com.mycompany.myapp",
    "prodDatabaseType": "postgresql",
    "reactive": false,
    "searchEngine": false,
    "serverPort": null,
    "serverSideOptions": [],
    "serviceDiscoveryType": false,
    "testFrameworks": [],
    "websocket": false,
    "withAdminUi": true
  }
}
Environment and Tools

openjdk version "17.0.8" 2023-07-18 OpenJDK Runtime Environment GraalVM CE 22.3.3 (build 17.0.8+7-jvmci-22.3-b22) OpenJDK 64-Bit Server VM GraalVM CE 22.3.3 (build 17.0.8+7-jvmci-22.3-b22, mixed mode, sharing)

git version 2.39.3 (Apple Git-145)

node: v18.17.1 npm: 9.6.7

Docker version 24.0.6, build ed223bc

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Employee {
  firstName String
  salary Long
}
search Employee with no

Entity configuration(s) entityName.json files generated in the .jhipster directory
Employee.json ``` { "applications": "*", "changelogDate": "20231006113137", "entityTableName": "employee", "fields": [ { "fieldName": "firstName", "fieldType": "String" }, { "fieldName": "salary", "fieldType": "Long" } ], "name": "Employee", "relationships": [], "searchEngine": "no" } ```
Browsers and Operating System

chrome , macos

qmonmert commented 12 months ago

@hide212131 I don't reproduce, I try with differents numeric fields and it seems to work image image image

hide212131 commented 12 months ago

@qmonmert Thank you for investigating the issue. I apologize for the lack of clarity in my initial description. The response message is correct; the issue lies with the request message.

request response
qmonmert commented 12 months ago

@hide212131 thanks for the precision, I confirm the bug