Openrefine: Cell types being set back to String

Created on 28 Mar 2019  路  7Comments  路  Source: OpenRefine/OpenRefine

Describe the bug
Cells which have been converted to non-string types of "number" or "boolean" are being set back to "string" on restarting OpenRefine (or possible on project save?)

To Reproduce
Steps to reproduce the behavior:

  1. Create a project
  2. Insert number or boolean values into a cell
  3. Check these have been correctly set by using GREL "value.type()"
  4. Restart OpenRefine
  5. Check the cell types by using GREL "value.type()"

Current Results
Before restarting the values show as the expected types
After restarting the values show as Strings

Expected behavior
Values should retain type as set

Screenshots
Before restart:
Screenshot 2019-03-28 at 09 32 56

After restart:
Screenshot 2019-03-28 at 09 34 08

Desktop (please complete the following information):

  • OS: MacOS Mojave
  • Browser Version: Safari Version 12.0.3 (14606.4.5)
  • JRE or JDK Version: JRE 1.8.0_72

OpenRefine (please complete the following information):

  • 3.2 beta

Additional context
Dates do not seem affected by this issue

bug Critical

All 7 comments

Possible this is related to #1996?

I agree this is important, it's probably linked to the Jackson migration.

@wetneb I've done some further investigation into this and #1996. It looks to me like the problem is with com.google.refine.modelCell.getValueasString https://github.com/OpenRefine/OpenRefine/blob/ebaad96dfc33f44b1a0904800cd8bdac7c655220/main/src/com/google/refine/model/Cell.java#L105 which leads "v" to always serialise to a string

In the case of booleans or numbers (of any type that can be represented as a number in JSON) then these should be serialized to their native types in JSON rather than as a string. I could probably fix this, but I'm not very confident.

I also feel that possibly this whole aspect of Cell.java might benefit from re-factoring using Jackson annotations (e.g. could the date processing done here be equally well handled by a @JsonFormat annotation? ) - but I don't have the knowledge to be sure about the best way to approach this.

Any views? I'm happy to try a PR which you can comment on if you want? Or do you already have this in hand?

@ostephens Thanks a lot for the investigation. Yes it looks like I have overlooked the type issue when rewriting this.

I am not working on this at the moment but solving this is clearly required before 3.2. A PR for this would be fantastic!

@wetneb is there any good intro to using Jackson annotations you'd recommend?

I found these ones helpful:

For this particular problem, I would say you could try by changing getValueAsString to return Object instead (and probably change the method name), returning the right object type for JSON聽serialization. Jackson will serialize Java's booleans as JSON booleans, and so on. If I remember correctly the ObjectMapper is already configured for date serialization. So I probably just made this method a lot more complicated (and a lot less correct) than it should be!

Closed by #2008

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wetneb picture wetneb  路  3Comments

thadguidry picture thadguidry  路  3Comments

kushthedude picture kushthedude  路  3Comments

dantexier picture dantexier  路  4Comments

tfmorris picture tfmorris  路  3Comments