OrientDB 1.6: DB export API produces malformed JSON and cannot be reimported
Hi, I think I have found a bug in exported DB. Scenario: OrientDB version 1.6 I have a class "_BB_FileAsset" and I have this piece of code that create and store a Map inside it:
[........]
//asset is an ODocument object, sizePattern is a String
Map<String,ORID> resizedMap=(Map<String,ORID>) asset.field("resized");
if (resizedMap==null) resizedMap=new HashMap<String,ORID>();
resizedMap.put(sizePattern, new ORecordBytes().fromStream(resizedImage).save().getIdentity());
asset.field("resized",resizedMap);
asset.save();
[.........]
So at the end I have a new field "resized" that is a Map of key/rid pairs and the rids point to serialized images.
To export the db, I use the following code:
ODatabaseExport oe = new ODatabaseExport(db, os, new OCommandOutputListener() {
@Override
public void onMessage(String m) {
Logger.info(m);
}
});
oe.setUseLineFeedForRecords(true);
oe.setIncludeManualIndexes(true);
oe.exportDatabase();
The resulting file is invalid because the "resized" fields of the Asset documents are not properly serialized. This line is from the exported file:
{
"@type":"d",
"@rid":"#18:0",
"@version":16,
"@class":"_BB_FileAsset",
"name":"arancino",
"contentType":"image/png",
"file":"#3:2",
"_links":"#11:9",
"_creation_date":1384513553080,
"id":"569814f6-8c65-469a-a6e3-3b3af614a963",
"_author":"admin",
"fileName":"arancino.png",
"contentLength":118233,
"_allowRead":["#4:0","#4:1","#4:2","#4:3","#4:4","#4:5","#4:6"],
"_allow":["#5:0"],
"_audit":"#3:3",
"_allowUpdate":["#4:0","#4:1","#4:2","#4:3","#4:4","#4:5","#4:6"],
"resized":{
"@fieldTypes":"_creation_date=t,contentLength=l,_allowRead=e,_allow=e,_allowUpdate=e"
}
How you can see after the "resized" key there isn't its value, there is just an open bracket followed by the @fieldTypes field. The lack of the closing braket causes an error when an import is executed.
Did you see any errors while exporting?
Yes, sorry, I missed it...
java.lang.ClassCastException: com.orientechnologies.orient.core.record.impl.ORecordBytes cannot be cast to com.orientechnologies.orient.core.record.im
pl.ODocument
at com.orientechnologies.orient.core.fetch.OFetchHelper.fetchMap(OFetchHelper.java:425)
at com.orientechnologies.orient.core.fetch.OFetchHelper.fetch(OFetchHelper.java:408)
at com.orientechnologies.orient.core.fetch.OFetchHelper.processRecord(OFetchHelper.java:365)
at com.orientechnologies.orient.core.fetch.OFetchHelper.fetch(OFetchHelper.java:83)
at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerJSON.toString(ORecordSerializerJSON.java:580)
at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerStringAbstract.toString(ORecordSerializerStringAb
stract.java:68)
at com.orientechnologies.orient.core.record.ORecordAbstract.toJSON(ORecordAbstract.java:211)
at com.orientechnologies.orient.core.db.tool.ODatabaseExport.exportRecord(ODatabaseExport.java:496)
at com.orientechnologies.orient.core.db.tool.ODatabaseExport.exportRecords(ODatabaseExport.java:182)
at com.orientechnologies.orient.core.db.tool.ODatabaseExport.exportDatabase(ODatabaseExport.java:107)
...
2013-11-18 18:41:24,014 - App: - ERROR - com.orientechnologies: application-akka.actor.default-dispatcher-4 Fetching error on record
#18:0
java.lang.ClassCastException: com.orientechnologies.orient.core.record.impl.ORecordBytes cannot be cast to com.orientechnologies.orient.core.record.im
pl.ODocument
at com.orientechnologies.orient.core.fetch.OFetchHelper.fetchMap(OFetchHelper.java:425) [orientdb-core-1.6.jar:1.6]
at com.orientechnologies.orient.core.fetch.OFetchHelper.fetch(OFetchHelper.java:408) [orientdb-core-1.6.jar:1.6]
at com.orientechnologies.orient.core.fetch.OFetchHelper.processRecord(OFetchHelper.java:365) [orientdb-core-1.6.jar:1.6]
at com.orientechnologies.orient.core.fetch.OFetchHelper.fetch(OFetchHelper.java:83) [orientdb-core-1.6.jar:1.6]
at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerJSON.toString(ORecordSerializerJSON.java:580) [or
ientdb-core-1.6.jar:1.6]
at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerStringAbstract.toString(ORecordSerializerStringAb
stract.java:68) [orientdb-core-1.6.jar:1.6]
at com.orientechnologies.orient.core.record.ORecordAbstract.toJSON(ORecordAbstract.java:211) [orientdb-core-1.6.jar:1.6]
at com.orientechnologies.orient.core.db.tool.ODatabaseExport.exportRecord(ODatabaseExport.java:496) [orientdb-core-1.6.jar:1.6]
at com.orientechnologies.orient.core.db.tool.ODatabaseExport.exportRecords(ODatabaseExport.java:182) [orientdb-core-1.6.jar:1.6]
at com.orientechnologies.orient.core.db.tool.ODatabaseExport.exportDatabase(ODatabaseExport.java:107) [orientdb-core-1.6.jar:1.6]
....
This is very strange. It seems that it tries to serialize the ORecordBytes linked by the ORIDs in the Map. But it is unnecessary, I think
Can you see that record if in the MAP has a link to any ORecordBytes?