@Test public void testSerializeWithMapping() throws SerDeException, JSONException { System.out.println("testSerializeWithMapping"); JsonSerDe serde = getMappedSerde(); System.out.println("serialize"); ArrayList<Object> row = new ArrayList<Object>(5); List<ObjectInspector> lOi = new LinkedList<ObjectInspector>(); List<String> fieldNames = new LinkedList<String>(); row.add(Boolean.TRUE); fieldNames.add("one"); lOi.add(ObjectInspectorFactory.getReflectionObjectInspector(Boolean.class, ObjectInspectorFactory.ObjectInspectorOptions.JAVA)); row.add(43.2f); fieldNames.add("two"); lOi.add(ObjectInspectorFactory.getReflectionObjectInspector(Float.class, ObjectInspectorFactory.ObjectInspectorOptions.JAVA)); final List<String> lst = new LinkedList<String>(); row.add(lst); fieldNames.add("three"); lOi.add(ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory .getReflectionObjectInspector(String.class, ObjectInspectorFactory.ObjectInspectorOptions.JAVA))); row.add("value1"); fieldNames.add("four"); lOi.add(ObjectInspectorFactory.getReflectionObjectInspector(String.class, ObjectInspectorFactory.ObjectInspectorOptions.JAVA)); row.add(7898); fieldNames.add("ts"); lOi.add(ObjectInspectorFactory.getReflectionObjectInspector(Integer.class, ObjectInspectorFactory.ObjectInspectorOptions.JAVA)); StructObjectInspector soi = ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, lOi); Object obj = serde.serialize(row, soi); assertTrue(obj instanceof Text); String objs = obj.toString(); String res = "{\"timestamp\":7898,\"two\":43.2,\"one\":true,\"three\":[],\"four\":\"value1\"}"; String[] r2 = res.substring(1,res.length() - 1).split(","); assertEquals(objs.length() , res.length() ); for(String s: r2) { assertTrue(objs.contains(s)); } }
@Override public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException { if (objInspector.getCategory() != Category.STRUCT) { throw new SerDeException(getClass().toString() + " can only serialize struct types, but we got: " + objInspector.getTypeName()); } JSONObject serializer = serializeStruct( obj, (StructObjectInspector) objInspector, columnNames); Text t = new Text(serializer.toString()); serializedDataSize = t.getBytes().length; return t; }
JsonSerDe extends AbstractSerDe { @Override public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException { if (objInspector.getCategory() != Category.STRUCT) { throw new SerDeException(getClass().toString() + " can only serialize struct types, but we got: " + objInspector.getTypeName()); } JSONObject serializer = serializeStruct( obj, (StructObjectInspector) objInspector, columnNames); Text t = new Text(serializer.toString()); serializedDataSize = t.getBytes().length; return t; } }
JsonSerDe extends AbstractSerDe { @Override public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException { if (objInspector.getCategory() != Category.STRUCT) { throw new SerDeException(getClass().toString() + " can only serialize struct types, but we got: " + objInspector.getTypeName()); } JSONObject serializer = serializeStruct( obj, (StructObjectInspector) objInspector, columnNames); Text t = new Text(serializer.toString()); serializedDataSize = t.getBytes().length; return t; }  }
JsonSerDe extends AbstractSerDe { @Override public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException { if (objInspector.getCategory() != Category.STRUCT) { throw new SerDeException(getClass().toString() + " can only serialize struct types, but we got: " + objInspector.getTypeName()); } JSONObject serializer = serializeStruct( obj, (StructObjectInspector) objInspector, columnNames); Text t = new Text(serializer.toString()); serializedDataSize = t.getBytes().length; return t; }  @Override void initialize(Configuration conf, Properties tbl); @Override Object deserialize(Writable w); @Override ObjectInspector getObjectInspector(); @Override Class<? extends Writable> getSerializedClass(); @Override Writable serialize(Object obj, ObjectInspector objInspector); Object serializeField(Object obj,
            ObjectInspector oi ); void onMalformedJson(String msg); @Override SerDeStats getSerDeStats(); }
JsonSerDe extends AbstractSerDe { @Override public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException { if (objInspector.getCategory() != Category.STRUCT) { throw new SerDeException(getClass().toString() + " can only serialize struct types, but we got: " + objInspector.getTypeName()); } JSONObject serializer = serializeStruct( obj, (StructObjectInspector) objInspector, columnNames); Text t = new Text(serializer.toString()); serializedDataSize = t.getBytes().length; return t; }  @Override void initialize(Configuration conf, Properties tbl); @Override Object deserialize(Writable w); @Override ObjectInspector getObjectInspector(); @Override Class<? extends Writable> getSerializedClass(); @Override Writable serialize(Object obj, ObjectInspector objInspector); Object serializeField(Object obj,
            ObjectInspector oi ); void onMalformedJson(String msg); @Override SerDeStats getSerDeStats(); static final Log LOG; static final String PROP_IGNORE_MALFORMED_JSON; static final String PROP_DOTS_IN_KEYS; static final String PROP_CASE_INSENSITIVE; static final String PROP_EXPLICIT_NULL; static final String PFX; }