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

Error converting double type to JSON and XML #60

Open
dgvivero opened this issue Oct 9, 2014 · 9 comments
Open

Error converting double type to JSON and XML #60

dgvivero opened this issue Oct 9, 2014 · 9 comments
Labels

Comments

@dgvivero
Copy link

dgvivero commented Oct 9, 2014

Hi, I have a resource to a single table that return a number but it's returned bad:
resource: select numcpb, tipocpb from cpbcab
it's return -> { "cpbcabs": [ { "tipocpb": "NPE", "numcpb": 1.00000001E8, } ] }
but I need that -> { "cpbcabs": [ { "tipocpb": "NPE", "numcpb": 100000202, } ] }
and thas it's metada info ->

What can I do to solve this issue?

@mooreds
Copy link
Contributor

mooreds commented Oct 9, 2014

Need a little more info to help you.

What database are you using? What is the column definition of that table ('cpbcab')?

What version of restsql are you using?

@dgvivero
Copy link
Author

dgvivero commented Oct 9, 2014

Hi , we use mysql
metadata is ->
""
I'm using version 8.7 and today test on 8.9
tnk.

@dgvivero
Copy link
Author

dgvivero commented Oct 9, 2014

I have problem with copy/paste that's column definition
column columnLabel="numcpb" columnName="numcpb" columnNumber="1" columnType="8" columnTypeName="DOUBLE" databaseName="gc_pruebas_cc" nonqueriedForeignKey="false" primaryKey="true" qualifiedColumnName="cpbcab.numcpb" qualifiedTableName="gc_pruebas_cc.cpbcab" readOnly="false" sequence="false" tableName="cpbcab"

@restsql
Copy link
Owner

restsql commented Oct 10, 2014

Diego,

I don't believe any recent changes would have created this issue. The framework retrieves numeric data from the database driver as Java objects and then serializes those objects (Integer, Long, Float, Double) to strings using default mechanisms. Unfortunately the default String representation of Float and Double uses scientific notation when the number is less than 10e-3 or greater than or equal to 10e7. I don't think there's anything I can suggest as a workaround.

This is odd behavior and I would like to change it. But I'll need to create the number format mechanism, a table with columns that go that past 7 digits (the largest numbers in the sakila database are 5 digits) and test cases. So this will take me some time.

Sorry for the trouble.

Mark

@restsql restsql added the bug label Oct 10, 2014
@dgvivero
Copy link
Author

Ohh, that's a problem this is a key field on my db so I have to change to other solution but anyway I'II be seeing your progress It's a good project.

@ipcsystems
Copy link

If you can change the type to a long (whole number without a fraction), there is not conversion to scientific notation for large values.

@mooreds
Copy link
Contributor

mooreds commented Oct 10, 2014

@ipcsystems you mean the datatype of the numcpb column in the database, correct? If so, this link may be helpful: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

@restsql
Copy link
Owner

restsql commented Oct 10, 2014

Dan I was mistakenly logged in on a different account when I made that comment.

Yes, change numcpb column type to drop the decimal portion. That will internally use an Integer or Long in restSQL and avoid the issue with scientific notation.

Thanks for the reference to alter table for MySQL. Here's the same for PostgreSQL: http://www.postgresql.org/docs/9.1/static/sql-altertable.html.

I understand changing a data type is not easy Diego. Let me know your timeframe for getting this addressed.

@dgvivero
Copy link
Author

Yes, we have a legacy system that come with this database and I 'm doing a webapp over it, so it's dificult change this table column from DOUBLE to a LONG, without some risk. but I will try on a test db.
thank's

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

No branches or pull requests

4 participants