Package org.openx.data.jsonserde.json

Examples of org.openx.data.jsonserde.json.JSONObject$Null


        JsonSerDe serde = getNumericSerde();
        Text line = new Text("{ cfloat:3.1415E02, cdouble:-1.65788E-12}");
       
  StructObjectInspector soi = (StructObjectInspector) serde.getObjectInspector();
 
  JSONObject result = (JSONObject) serde.deserialize(line);
 
        StructField sf = soi.getStructFieldRef("cfloat");
  assertTrue(sf.getFieldObjectInspector() instanceof JavaStringFloatObjectInspector);
        JavaStringFloatObjectInspector foi = (JavaStringFloatObjectInspector) sf.getFieldObjectInspector();
  assertEquals(3.1415E02 , foi.get(result.get("cfloat")),0.001);
 
  sf = soi.getStructFieldRef("cdouble");
  assertTrue(sf.getFieldObjectInspector() instanceof JavaStringDoubleObjectInspector);
        JavaStringDoubleObjectInspector doi = (JavaStringDoubleObjectInspector) sf.getFieldObjectInspector();
  assertEquals(-1.65788E-12 , doi.get(result.get("cdouble")),0.001);
    }
View Full Code Here


         JsonSerDe serde = getNumericSerde();
        Text line = new Text("{ cboolean:true, ctinyint:0x01, csmallint:0x0a, cint:0Xabcd,cbigint:0xabcd121212, cfloat:3.1415, cdouble:43424234234.4243423}");
       
  StructObjectInspector soi = (StructObjectInspector) serde.getObjectInspector();
 
  JSONObject result = (JSONObject) serde.deserialize(line);
 
        StructField sf = soi.getStructFieldRef("ctinyint");
 
  assertTrue(sf.getFieldObjectInspector() instanceof JavaStringByteObjectInspector);
        JavaStringByteObjectInspector boi = (JavaStringByteObjectInspector) sf.getFieldObjectInspector();
  assertEquals(1, boi.get(result.get("ctinyint")));
       
       
  sf = soi.getStructFieldRef("csmallint");
  assertTrue(sf.getFieldObjectInspector() instanceof JavaStringShortObjectInspector);
        JavaStringShortObjectInspector shoi = (JavaStringShortObjectInspector) sf.getFieldObjectInspector();
  assertEquals(10, shoi.get(result.get("csmallint")));
 
 
  sf = soi.getStructFieldRef("cint");
  assertTrue(sf.getFieldObjectInspector() instanceof JavaStringIntObjectInspector);
        JavaStringIntObjectInspector oi = (JavaStringIntObjectInspector) sf.getFieldObjectInspector();
  assertEquals(43981, oi.get(result.get("cint")));
 
  sf = soi.getStructFieldRef("cbigint");
  assertTrue(sf.getFieldObjectInspector() instanceof JavaStringLongObjectInspector);
        JavaStringLongObjectInspector bioi = (JavaStringLongObjectInspector) sf.getFieldObjectInspector();
  assertEquals(737879921170L , bioi.get(result.get("cbigint")));

       
    }
View Full Code Here

  @Test
  public void testTimestampDeSerializeNumericTimestampWithNanoseconds() throws Exception {
    // Test that timestamp object can be deserialized
    Writable w = new Text("{\"one\":true,\"five\":1367801925.123}");
//
    JSONObject result = (JSONObject) instance.deserialize(w);
     StructObjectInspector soi = (StructObjectInspector) instance.getObjectInspector();
    JavaStringTimestampObjectInspector jstOi = (JavaStringTimestampObjectInspector)
            soi.getStructFieldRef("five").getFieldObjectInspector();
    assertEquals(getDate("2013-05-05 17:58:45.123"),
            jstOi.getPrimitiveJavaObject(result.get("five")) );
  }
View Full Code Here

       
        try {
            String txt = rowText.toString().trim();
           
            if(txt.startsWith("{")) {
                jObj = new JSONObject(txt);
            } else if (txt.startsWith("[")){
                jObj = new JSONArray(txt);
            }
        } catch (JSONException e) {
            // If row is not a JSON object, make the whole row NULL
            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.");
            }
        }
 
View Full Code Here

            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;
    }
View Full Code Here

        // do nothing for null struct
        if (null == obj) {
            return null;
        }

        JSONObject result = new JSONObject();
       
        List<? extends StructField> fields = soi.getAllStructFieldRefs();
       
        for (int i =0; i< fields.size(); i++) {
            StructField sf = fields.get(i);
            Object data = soi.getStructFieldData(obj, sf);

            if (null != data) {
                try {
                    // we want to serialize columns with their proper HIVE name,
                    // not the _col2 kind of name usually generated upstream
                    result.put(
                            getSerializedFieldName(columnNames, i, sf),
                            serializeField(
                                data,
                                sf.getFieldObjectInspector()));
                   
View Full Code Here

     * @return
     */
    private JSONObject serializeMap(Object obj, MapObjectInspector moi) {
        if (obj==null) { return null; }
       
        JSONObject jo = new JSONObject()
        Map m = moi.getMap(obj);
       
        for(Object k : m.keySet()) {
            try {
                jo.put(
                        serializeField(k, moi.getMapKeyObjectInspector()).toString(),
                        serializeField(m.get(k), moi.getMapValueObjectInspector()) );
            } catch (JSONException ex) {
                LOG.warn("Problem serializing map");
            }
View Full Code Here

  @Test
  public void testDeSerialize() throws Exception {
    // Test that timestamp object can be deserialized
    Writable w = new Text("{ \"ts\":\"2014-08-25T00:24:27.41103928Z\", \"t\":36529, \"Request\":{ \"path\":\"/foo/bar\", \"query\":{\"baz\": [\"ban\"]}, \"headers\":{ \"Accept\":[\"image/webp,*/*;q=0.8\"], \"Accept-Encoding\":[\"identity\"], \"Accept-Language\":[\"en-US,en;q=0.8\"], \"Connection\":[\"keep-alive\"], \"Referer\":[\"http://foo.com/bar\"], \"User-Agent\":[\"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"] }, \"ip\":\"10.0.0.1\" } }");

    JSONObject result = (JSONObject) instance.deserialize(w);
   
    StructObjectInspector soi = (StructObjectInspector) instance.getObjectInspector();
   
    StructField tSF = soi.getStructFieldRef("t");
    assertEquals(36529, ((JavaStringIntObjectInspector)tSF.getFieldObjectInspector()).get(soi.getStructFieldData(result, tSF )));
View Full Code Here

  @Test
  public void testDeSerialize() throws Exception {
    // Test that timestamp object can be deserialized
    Writable w = new Text("{\"country\":\"Switzerland\",\"languages\":\"Italian\",\"religions\":\"\"}");
   
    JSONObject result = (JSONObject) instance.deserialize(w);
   
    StructObjectInspector soi = (StructObjectInspector) instance.getObjectInspector();
   
    StructField sfr = soi.getStructFieldRef("religions");
   
View Full Code Here

  public Map<?, ?> getMap(Object data) {
    if (JsonObjectInspectorUtils.checkObject(data) == null) {
      return null;
    }
   
    JSONObject jObj = (JSONObject) data;
   
    return new JSONObjectMapAdapter(jObj);
  }
View Full Code Here

TOP

Related Classes of org.openx.data.jsonserde.json.JSONObject$Null

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.