List typesDefined = types.define(types2define);
// Create an empty data graph and add a root object, an instance of customerType
//
DataGraph dataGraph = SDOUtil.createDataGraph();
Type customerTypeDefined = (Type) typesDefined.get(1);
DataObject customer1 = dataGraph.createRootObject(customerTypeDefined);
customer1.setInt("custNum", 1);
customer1.set("firstName", "John");
customer1.set("lastName", "Adams");
DataObject address = customer1.createDataObject("address");
address.set("addrSt", "577 Airport Blvd");
SDOUtil.registerDataGraphTypes(dataGraph, typesDefined);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SDOUtil.saveDataGraph(dataGraph, baos, null);
//SDOUtil.saveDataGraph(dataGraph, System.out, null);
TypeHelper deserializingTypeHelper = SDOUtil.createTypeHelper();
// The following is a kludge to force deserialization of metadata into a different TypeHelper (scope)
// TBD figure out a proper non-EMF way to do this.
Map options = new HashMap();
Object differentFromSerializing = ((TypeHelperImpl) deserializingTypeHelper).getExtendedMetaData();
options.put(XMLResource.OPTION_EXTENDED_META_DATA, differentFromSerializing);
byte[] serialized = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(serialized);
DataGraph loadedDataGraph = SDOUtil.loadDataGraph(bais, options);
DataObject loadedRootObject = loadedDataGraph.getRootObject();
assertNotSame(loadedRootObject.getType(), customer1.getType());
// EqualityHelper requires same Type
assertEquals(loadedRootObject.getInt("custNum"), customer1.getInt("custNum"));
assertEquals(loadedRootObject.get("firstName"), customer1.get("firstName"));