Java Code Examples for org.apache.ignite.binary.BinaryObject#type()

The following examples show how to use org.apache.ignite.binary.BinaryObject#type() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BinaryObjectBuilderDefaultMappersSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testMetaData2() throws Exception {
    BinaryObjectBuilder builder = builder("org.test.MetaTest2");

    builder.setField("objectField", "a", Object.class);

    BinaryObject bo = builder.build();

    BinaryType meta = bo.type();

    assertEquals(expectedTypeName("org.test.MetaTest2"), meta.typeName());
    assertEquals("Object", meta.fieldTypeName("objectField"));
}
 
Example 2
Source File: GridDefaultBinaryMappersBinaryMetaDataSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testSerializedObject() throws Exception {
    TestObject1 obj = new TestObject1();

    obj.intVal = 10;
    obj.strVal = "str";
    obj.arrVal = new byte[] {2, 4, 6};
    obj.obj1Val = null;
    obj.obj2Val = new TestObject2();
    obj.decVal = BigDecimal.ZERO;
    obj.decArrVal = new BigDecimal[] { BigDecimal.ONE };

    BinaryObject po = binaries().toBinary(obj);

    info(po.toString());

    BinaryType meta = po.type();

    assertNotNull(meta);

    assertEquals(expectedTypeName(TestObject1.class.getName()), meta.typeName());

    Collection<String> fields = meta.fieldNames();

    assertEquals(7, fields.size());

    assertTrue(fields.contains("intVal"));
    assertTrue(fields.contains("strVal"));
    assertTrue(fields.contains("arrVal"));
    assertTrue(fields.contains("obj1Val"));
    assertTrue(fields.contains("obj2Val"));
    assertTrue(fields.contains("decVal"));
    assertTrue(fields.contains("decArrVal"));

    assertEquals("int", meta.fieldTypeName("intVal"));
    assertEquals("String", meta.fieldTypeName("strVal"));
    assertEquals("byte[]", meta.fieldTypeName("arrVal"));
    assertEquals("Object", meta.fieldTypeName("obj1Val"));
    assertEquals("Object", meta.fieldTypeName("obj2Val"));
    assertEquals("decimal", meta.fieldTypeName("decVal"));
    assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
}
 
Example 3
Source File: BinaryObjectBuilderDefaultMappersSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testMetaData() throws Exception {
    BinaryObjectBuilder builder = builder("org.test.MetaTest");

    builder.setField("intField", 1);
    builder.setField("byteArrayField", new byte[] {1, 2, 3});

    BinaryObject po = builder.build();

    BinaryType meta = po.type();

    assertEquals(expectedTypeName("org.test.MetaTest"), meta.typeName());

    Collection<String> fields = meta.fieldNames();

    assertEquals(2, fields.size());

    assertTrue(fields.contains("intField"));
    assertTrue(fields.contains("byteArrayField"));

    assertEquals("int", meta.fieldTypeName("intField"));
    assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));

    builder = builder("org.test.MetaTest");

    builder.setField("intField", 2);
    builder.setField("uuidField", UUID.randomUUID());

    po = builder.build();

    meta = po.type();

    assertEquals(expectedTypeName("org.test.MetaTest"), meta.typeName());

    fields = meta.fieldNames();

    assertEquals(3, fields.size());

    assertTrue(fields.contains("intField"));
    assertTrue(fields.contains("byteArrayField"));
    assertTrue(fields.contains("uuidField"));

    assertEquals("int", meta.fieldTypeName("intField"));
    assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
    assertEquals("UUID", meta.fieldTypeName("uuidField"));
}