DataSchema { public DataObject toDataObject() { DataObject dataObject = new DataObject(); List<Field> fields = cachedFields(this.getClass()); for (int i = 0; i < fields.size(); i++) { FieldParameter fieldParameter = fieldParameterMap.get(fields.get(i)); if (fieldParameter != null) { try { if (!fields.get(i).isAccessible()) { fields.get(i).setAccessible(true); } Object value = fields.get(i).get(this); if (value != null) { dataObject.set(fieldParameter.Code(), value); } } catch (IllegalAccessException e) { logger.error("Failed to parse DataSchema", e); } } } return dataObject; } protected  DataSchema(); protected  DataSchema(DataObject data); boolean isValid(); DataObject toDataObject();  }
@Test public void testToDataObject() { TestMessage testMessage = new TestMessage(); testMessage.id = ID; testMessage.name = NAME; DataObject dataObject = testMessage.toDataObject(); Assert.assertEquals(ID, dataObject.get((byte)0).value); Assert.assertEquals(NAME, dataObject.get((byte)1).value); TestMessage testMessage2 = new TestMessage(); testMessage2.id = ID2; testMessage2.name = NAME2; DataObject dataObject2 = testMessage2.toDataObject(); Assert.assertEquals(ID2, dataObject2.get((byte)0).value); Assert.assertEquals(NAME2, dataObject2.get((byte)1).value); }