@Test public void testDeserialize() throws Exception { JsonSerDe instance = new JsonSerDe(); initialize(instance); System.out.println("deserialize"); Writable w = new Text("{\"one\":true,\"three\":[\"red\",\"yellow\",\"orange\"],\"two\":19.5,\"four\":\"poop\"}"); JSONObject result = (JSONObject) instance.deserialize(w); assertEquals("poop",result.get("four")); assertTrue(result.get("three") instanceof JSONArray); assertTrue( ((JSONArray)result.get("three")).get(0) instanceof String ); assertEquals("red", ((JSONArray)result.get("three")).get(0)); }
@Override public Object deserialize(Writable w) throws SerDeException { Text rowText = (Text) w; deserializedDataSize = rowText.getBytes().length; Object jObj = null; try { String txt = rowText.toString().trim(); if(txt.startsWith("{")) { jObj = new JSONObject(txt); } else if (txt.startsWith("[")){ jObj = new JSONArray(txt); } } catch (JSONException e) { onMalformedJson("Row is not a valid JSON Object - JSONException: " + e.getMessage()); try { jObj = new JSONObject("{}"); } catch (JSONException ex) { onMalformedJson("Error parsing empty row. This should never happen."); } } return jObj; }
JsonSerDe extends AbstractSerDe { @Override public Object deserialize(Writable w) throws SerDeException { Text rowText = (Text) w; deserializedDataSize = rowText.getBytes().length; Object jObj = null; try { String txt = rowText.toString().trim(); if(txt.startsWith("{")) { jObj = new JSONObject(txt); } else if (txt.startsWith("[")){ jObj = new JSONArray(txt); } } catch (JSONException e) { onMalformedJson("Row is not a valid JSON Object - JSONException: " + e.getMessage()); try { jObj = new JSONObject("{}"); } catch (JSONException ex) { onMalformedJson("Error parsing empty row. This should never happen."); } } return jObj; } }
JsonSerDe extends AbstractSerDe { @Override public Object deserialize(Writable w) throws SerDeException { Text rowText = (Text) w; deserializedDataSize = rowText.getBytes().length; Object jObj = null; try { String txt = rowText.toString().trim(); if(txt.startsWith("{")) { jObj = new JSONObject(txt); } else if (txt.startsWith("[")){ jObj = new JSONArray(txt); } } catch (JSONException e) { onMalformedJson("Row is not a valid JSON Object - JSONException: " + e.getMessage()); try { jObj = new JSONObject("{}"); } catch (JSONException ex) { onMalformedJson("Error parsing empty row. This should never happen."); } } return jObj; }  }
JsonSerDe extends AbstractSerDe { @Override public Object deserialize(Writable w) throws SerDeException { Text rowText = (Text) w; deserializedDataSize = rowText.getBytes().length; Object jObj = null; try { String txt = rowText.toString().trim(); if(txt.startsWith("{")) { jObj = new JSONObject(txt); } else if (txt.startsWith("[")){ jObj = new JSONArray(txt); } } catch (JSONException e) { onMalformedJson("Row is not a valid JSON Object - JSONException: " + e.getMessage()); try { jObj = new JSONObject("{}"); } catch (JSONException ex) { onMalformedJson("Error parsing empty row. This should never happen."); } } return jObj; }  @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 Object deserialize(Writable w) throws SerDeException { Text rowText = (Text) w; deserializedDataSize = rowText.getBytes().length; Object jObj = null; try { String txt = rowText.toString().trim(); if(txt.startsWith("{")) { jObj = new JSONObject(txt); } else if (txt.startsWith("[")){ jObj = new JSONArray(txt); } } catch (JSONException e) { onMalformedJson("Row is not a valid JSON Object - JSONException: " + e.getMessage()); try { jObj = new JSONObject("{}"); } catch (JSONException ex) { onMalformedJson("Error parsing empty row. This should never happen."); } } return jObj; }  @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; }