Search in sources :

Example 16 with ORecordSerializer

use of com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer in project orientdb by orientechnologies.

the class CRUDDocumentPhysicalTest method testSerialization.

public void testSerialization() {
    ORecordSerializer current = ODatabaseDocumentTx.getDefaultSerializer();
    ODatabaseDocumentTx.setDefaultSerializer(ORecordSerializerSchemaAware2CSV.INSTANCE);
    ODatabaseDocumentInternal oldDb = ODatabaseRecordThreadLocal.INSTANCE.get();
    ORecordSerializer dbser = oldDb.getSerializer();
    ((ODatabaseDocumentTx) oldDb).setSerializer(ORecordSerializerSchemaAware2CSV.INSTANCE);
    final byte[] streamOrigin = "Account@html:{\"path\":\"html/layout\"},config:{\"title\":\"Github Admin\",\"modules\":(githubDisplay:\"github_display\")},complex:(simple1:\"string1\",one_level1:(simple2:\"string2\"),two_levels:(simple3:\"string3\",one_level2:(simple4:\"string4\")))".getBytes();
    ODocument doc = (ODocument) ORecordSerializerSchemaAware2CSV.INSTANCE.fromStream(streamOrigin, new ODocument(), null);
    doc.field("out");
    final byte[] streamDest = ORecordSerializerSchemaAware2CSV.INSTANCE.toStream(doc, false);
    Assert.assertEquals(streamOrigin, streamDest);
    ODatabaseDocumentTx.setDefaultSerializer(current);
    ((ODatabaseDocumentTx) oldDb).setSerializer(dbser);
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ORecordSerializer(com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ORecordSerializer (com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer)16 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 ORecordId (com.orientechnologies.orient.core.id.ORecordId)5 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 Test (org.testng.annotations.Test)4 IOException (java.io.IOException)3 OException (com.orientechnologies.common.exception.OException)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2 Test (org.junit.Test)2 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)1 OIOException (com.orientechnologies.common.io.OIOException)1 OCommandCache (com.orientechnologies.orient.core.cache.OCommandCache)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 ORecordOperation (com.orientechnologies.orient.core.db.record.ORecordOperation)1 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)1 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)1 OSerializationException (com.orientechnologies.orient.core.exception.OSerializationException)1 OTransactionAbortedException (com.orientechnologies.orient.core.exception.OTransactionAbortedException)1 OTransactionException (com.orientechnologies.orient.core.exception.OTransactionException)1 ORID (com.orientechnologies.orient.core.id.ORID)1