Unable to import entity with BigDecimal if has percent Number Format

Hi, I have an entity (Coupon) with a BigDecimal property (discount). I gave it a Number Format of ##0.0000%. I can export the entity as JSON data but I cannot import it. I believe this is a bug.

Steps:

  1. Open sample project. test-import.zip (86.7 KB)

  2. Create Coupon: name = Test, discount = 1.23%. [Due to the Number Format, the screen enforces the value in this format. The database stores 0.0123, which is great.]

  3. Go to Entity Inspector. Export Coupon as JSON. [Notice the file contains the discount as 0.012300000. This is fine in my opinion.]

  4. Attempt to import the exported file.

Expected result:

  • Import successful.

Actual result:

  • Import failed.

Stack trace:

com.haulmont.cuba.core.app.serialization.EntitySerializationException: An error occurred while parsing property. Type [AdaptiveNumberFormat<BigDecimal>]. Value [0.012300000].
    at com.haulmont.cuba.core.app.serialization.EntitySerialization$EntityDeserializer.readSimpleProperty(EntitySerialization.java:567) ~[cuba-global-6.10.2.jar:6.10.2]
...
Caused by: java.text.ParseException: Unparseable number: "0.012300000"
    at com.haulmont.chile.core.datatypes.impl.NumberDatatype.parse(NumberDatatype.java:79) ~[cuba-global-6.10.2.jar:6.10.2]
...

Notes:

  • By debugging the application, I can see that the NumberDatatype object is using a formatPattern value of the Number Format I gave (##0.0000%).
  • I think the NumberDatatype should just use a standard NumberFormat for any decimal value. That is my preference.
  • But it would also work if the export logic exported the value in the specified number format, e.g. 1.23%.

Hi Keith,

Thank you for reporting the problem, we’ve created an issue for it.

Thank you for the fix in 6.10.3.