Closed maggu2810 closed 5 years ago
Very simple example to reproduce:
public static void main(final String[] args) throws IOException {
final Path tmpDir = Files.createTempDirectory(null);
tmpDir.toFile().deleteOnExit();
final Path userdata = tmpDir.resolve("userdata");
userdata.toFile().mkdir();
System.setProperty(ConfigConstants.USERDATA_DIR_PROG_ARGUMENT, userdata.toString());
final MapDbStorageService storageService = new MapDbStorageService();
storageService.activate();
try {
DeletableStorage<TestDTO> storage = storageService.getStorage("dummy");
try {
final TestDTO test = new TestDTO();
test.var0 = "@@@";
storage.put("t1", test);
final TestDTO testRestored = storage.get("t1");
if (testRestored != null) {
System.out.println(test.var0 + " => " + testRestored.var0);
} else {
System.err.println("deserialization failed");
}
} finally {
storage.delete();
}
} finally {
storageService.deactivate();
}
}
json
looks like: org.eclipse.smarthome.storage.mapdb.internal.StorageTest$TestDTO@@@{"var0":"@@@"}
valueTypeName
looks like: org.eclipse.smarthome.storage.mapdb.internal.StorageTest$TestDTO
valueAsString
looks like: {"var0":"
As you can seen valueAsString
is not valid JSON.
The simple fix would be to change json.split(TYPE_SEPARATOR)
to json.split(TYPE_SEPARATOR, 2)
.
After that
valueAsString
looks like: {"var0":"@@@"}
On serialization the MapDB storage contains that part of code:
On deserialization this part of code is used:
IMHO this is wrong. We should use the limit parameter for the split that we do not want more then two parts. Using the current approach, I assume the deserialization of an JSON string (value as string) that looks like:
will be splitted as well.