-
Notifications
You must be signed in to change notification settings - Fork 781
JSON storage BigDecimal scaling regression #3774
Comments
I just checked the Json DB implementation - the mentioned workaround indeed got lost with #3225. The database implementation itself actually handles precisions "correctly", i.e. it does not add the trailing The config normalization also ensures that INTEGER configuration values are converted to a a BigDecimal with 0 scale. So while I'd love to find out how these values originally get into the database, it still can't hurt to apply the same workaround again. I will create a PR to make it more robust in this area. |
This basically re-introduces the same fallback mechanism that was already implemented with eclipse-archived#2685 but got lost with fixes eclipse-archived#3774 Signed-off-by: Simon Kaufmann <[email protected]>
This basically re-introduces the same fallback mechanism that was already implemented with eclipse-archived#2685 but got lost with fixes eclipse-archived#3774 Signed-off-by: Simon Kaufmann <[email protected]>
This basically re-introduces the same fallback mechanism that was already implemented with eclipse-archived#2685 but got lost with eclipse-archived#3225. fixes eclipse-archived#3774 Signed-off-by: Simon Kaufmann <[email protected]>
Oh, that's indeed a very ugly turn which I missed. Interesting... Very good analysis! I looks like so far the The proper fix of course would be to serialize the object to a strong before we put it into the outer map. However, that would lead to all objects being persisted as strings which include escaped json. Absolutely unreadable. That would contradict the original idea of the JsonDB: having a persistence format which is easily human-readable. Also it would render all existing JsonDBs useless. Therefore I'll try to fix the |
As it turned out, the current Map deserializer was not very effective in converting numbers to BigDecimals as it took itself out of the game when deserializing the outer map which JsonStorage adds itself. Hence a property map within an entity lost its normalization. This could have been compensated again during read by simply cutting off the trailing ".0"s, but this still led to the awkward situation that the numbers in the serialized format were altered and looked different of what would have been expected. fixes eclipse-archived#3774 Signed-off-by: Simon Kaufmann <[email protected]>
I have updated the PR. As thanks to your help we now found the root-cause, I removed the workaround again for now. I'd leave it open for discussion whether we should prefer rather stability (i.e. read the same what you wrote before) or automated error correction (i.e. cut off trailing @wborn @cdjackson @maggu2810 WDYT? |
Thanks for having another look at the code @SJKA. After doing some more testing I again run into deserialization issues with the updated PR code. My "300" values again get deserialized into "300.0". I've tested a new OH 2.2.0-SNAPSHOT, empty initial database and updated the Json Storage bundle so it contains the PR code. I can actually reproduce this in the new unit tests by making the private class DummyObject {
public Map<String, Object> myMap = new HashMap<String, Object>();
public List<Object> channels = new ArrayList<>();
public DummyObject() {
myMap.put("testShort", Short.valueOf("12"));
myMap.put("testInt", Integer.valueOf("12"));
myMap.put("testLong", Long.valueOf("12"));
myMap.put("testDouble", Double.valueOf("12.12"));
myMap.put("testFloat", Float.valueOf("12.12"));
myMap.put("testBigDecimal", new BigDecimal(12));
myMap.put("testBoolean", true);
myMap.put("testString", "hello world");
Map<String, Object> childMap = new HashMap<String, Object>();
childMap.put("testChildLong", Long.valueOf("12"));
channels.add(childMap);
}
} The test fails because |
As it turned out, the current Map deserializer was not very effective in converting numbers to BigDecimals as it took itself out of the game when deserializing the outer map which JsonStorage adds itself. Hence a property map within an entity lost its normalization. This could have been compensated again during read by simply cutting off the trailing ".0"s, but this still led to the awkward situation that the numbers in the serialized format were altered and looked different of what would have been expected. Therefore this change * Distinguishes the "outer map" (i.e. the internal data structure of the JsonStorage and the inner entity structures * Uses two different Gson instances for handling those two structures individually * Lets JsonStorage internally keep JsonElement structures _always_ * Registers a custom deserializer for Configuration which handles the custom number-to-BigDecimal conversion fixes eclipse-archived#3774 Signed-off-by: Simon Kaufmann <[email protected]>
As it turned out, the current Map deserializer was not very effective in converting numbers to BigDecimals as it took itself out of the game when deserializing the outer map which JsonStorage adds itself. Hence a property map within an entity lost its normalization. This could have been compensated again during read by simply cutting off the trailing ".0"s, but this still led to the awkward situation that the numbers in the serialized format were altered and looked different of what would have been expected. Therefore this change * Distinguishes the "outer map" (i.e. the internal data structure of the JsonStorage and the inner entity structures * Uses two different Gson instances for handling those two structures individually * Lets JsonStorage internally keep JsonElement structures _always_ * Registers a custom deserializer for Configuration which handles the custom number-to-BigDecimal conversion fixes eclipse-archived#3774 Signed-off-by: Simon Kaufmann <[email protected]>
As it turned out, the current Map deserializer was not very effective in converting numbers to BigDecimals as it took itself out of the game when deserializing the outer map which JsonStorage adds itself. Hence a property map within an entity lost its normalization. This could have been compensated again during read by simply cutting off the trailing ".0"s, but this still led to the awkward situation that the numbers in the serialized format were altered and looked different of what would have been expected. Therefore this change * Distinguishes the "outer map" (i.e. the internal data structure of the JsonStorage and the inner entity structures * Uses two different Gson instances for handling those two structures individually * Lets JsonStorage internally keep JsonElement structures _always_ * Registers a custom deserializer for Configuration which handles the custom number-to-BigDecimal conversion fixes eclipse-archived#3774 Signed-off-by: Simon Kaufmann <[email protected]>
* migrate json storage service test to java Signed-off-by: Simon Kaufmann <[email protected]> * fix potential NPE in json storage if backup folder does not exist Signed-off-by: Simon Kaufmann <[email protected]> * fix number deserialization on Json Storage As it turned out, the current Map deserializer was not very effective in converting numbers to BigDecimals as it took itself out of the game when deserializing the outer map which JsonStorage adds itself. Hence a property map within an entity lost its normalization. This could have been compensated again during read by simply cutting off the trailing ".0"s, but this still led to the awkward situation that the numbers in the serialized format were altered and looked different of what would have been expected. Therefore this change * Distinguishes the "outer map" (i.e. the internal data structure of the JsonStorage and the inner entity structures * Uses two different Gson instances for handling those two structures individually * Lets JsonStorage internally keep JsonElement structures _always_ * Registers a custom deserializer for Configuration which handles the custom number-to-BigDecimal conversion fixes #3774 Signed-off-by: Simon Kaufmann <[email protected]> * [jsondb] using dedicated storage entry object instead of a map Signed-off-by: Simon Kaufmann <[email protected]>
After updating to openHAB 2.1.0 I encounter again BigDecimal scaling issues. I.e. longs are stored as decimals in the jsondb files. Because of this the LIFX binding (and other bindings) revert to default values and log warnings like:
In
org.eclipse.smarthome.core.thing.Thing.json
the parameters show up like:I'm using:
@cdjackson originally fixed this with PR #2685.
The text was updated successfully, but these errors were encountered: