Object obj = serde.serialize(row, soi);
Object obj = serde.serialize(row, soi);
Object result = instance.serialize(row, soi);
@Test public void testExplicitNullValue() throws SerDeException, IOException { System.out.println("testExplicitNullValue"); JsonSerDe serde = new JsonSerDe(); Configuration conf = null; Properties tbl = new Properties(); tbl.setProperty(serdeConstants.LIST_COLUMNS, "stringCol,nullCol,missingCol"); tbl.setProperty(serdeConstants.LIST_COLUMN_TYPES, "string,string,string"); // Set 'explicit.null' to true tbl.setProperty(JsonSerDe.PROP_EXPLICIT_NULL, "true"); serde.initialize(conf, tbl); StructObjectInspector soi = (StructObjectInspector) serde.getObjectInspector(); // Load json string with one 'null' value and one 'missing' value Object res = serde.deserialize(new Text("{\"stringCol\":\"str\",\"nullCol\":null}")); // Get the serialized json string String jsonStr = serde.serialize(res, soi).toString(); assertTrue(soi.getStructFieldData(res, soi.getStructFieldRef("stringCol")).equals("str")); assertNull(soi.getStructFieldData(res, soi.getStructFieldRef("nullCol"))); assertNull(soi.getStructFieldData(res, soi.getStructFieldRef("missingCol"))); assertEquals(jsonStr,"{\"nullCol\":null,\"stringCol\":\"str\",\"missingCol\":null}"); }
@Test public void testExplicitNullValueDefault() throws SerDeException, IOException { System.out.println("testExplicitNullValue"); JsonSerDe serde = new JsonSerDe(); Configuration conf = null; Properties tbl = new Properties(); tbl.setProperty(serdeConstants.LIST_COLUMNS, "stringCol,nullCol,missingCol"); tbl.setProperty(serdeConstants.LIST_COLUMN_TYPES, "string,string,string"); serde.initialize(conf, tbl); StructObjectInspector soi = (StructObjectInspector) serde.getObjectInspector(); // Load json string with one 'null' value and one 'missing' value Object res = serde.deserialize(new Text("{\"stringCol\":\"str\",\"nullCol\":null}")); // Get the serialized json string String jsonStr = serde.serialize(res, soi).toString(); assertTrue(soi.getStructFieldData(res, soi.getStructFieldRef("stringCol")).equals("str")); assertNull(soi.getStructFieldData(res, soi.getStructFieldRef("nullCol"))); assertNull(soi.getStructFieldData(res, soi.getStructFieldRef("missingCol"))); assertEquals(jsonStr,"{\"stringCol\":\"str\"}"); }
String jsonStr = serde.serialize(res, soi).toString();