Package org.openx.data.jsonserde.json

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


  @Override
  public int getMapSize(Object data) {
    if (JsonObjectInspectorUtils.checkObject(data) == null) {
      return -1;
    }
     JSONObject jObj = (JSONObject) data;
    return jObj.length();
  }
View Full Code Here


  public Object getMapValueElement(Object data, Object key) {
    if (JsonObjectInspectorUtils.checkObject(data) == null) {
      return -1;
    }
   
     JSONObject jObj = (JSONObject) data;
        try {
            Object obj = jObj.get(key.toString());
            if(JSONObject.NULL == obj) {
                return null;
            } else {
                return obj;
            }
View Full Code Here

  @Test
  public void testDeSerialize() throws Exception {
    // Test that timestamp object can be deserialized
    Writable w = new Text("{ \"kind\": \"youtube#videoListResponse\", \"etag\": \"\\\"79S54kzisD_9SOTfQLu_0TVQSpY/mYlS4-ghMGhc1wTFCwoQl3IYDZc\\\"\", \"pageInfo\": { \"totalResults\": 1, \"resultsPerPage\": 1 }, \"items\": [ { \"kind\": \"youtube#video\", \"etag\": \"\\\"79S54kzisD_9SOTfQLu_0TVQSpY/A4foLs-VO317Po_ulY6b5mSimZA\\\"\", \"id\": \"wHkPb68dxEw\", \"statistics\": { \"viewCount\": \"9211\", \"likeCount\": \"79\", \"dislikeCount\": \"11\", \"favoriteCount\": \"0\", \"commentCount\": \"29\" }, \"topicDetails\": { \"topicIds\": [ \"/m/02mjmr\" ], \"relevantTopicIds\": [ \"/m/0cnfvd\", \"/m/01jdpf\" ] } } ] }");

    JSONObject result = (JSONObject) instance.deserialize(w);
   
    StructObjectInspector soi = (StructObjectInspector) instance.getObjectInspector();
   
    assertEquals("youtube#videoListResponse", soi.getStructFieldData(result, soi.getStructFieldRef("kind")));
    assertEquals("\"79S54kzisD_9SOTfQLu_0TVQSpY/mYlS4-ghMGhc1wTFCwoQl3IYDZc\""
View Full Code Here

  @Test
  public void testTimestampDeSerialize() throws Exception {
    // Test that timestamp object can be deserialized
    Writable w = new Text("{\"one\":true,\"five\":\"2013-03-27 23:18:40\"}");

    JSONObject result = (JSONObject) instance.deserialize(w);
   
    StructObjectInspector soi = (StructObjectInspector) instance.getObjectInspector();
   
    JavaStringTimestampObjectInspector jstOi = (JavaStringTimestampObjectInspector)
            soi.getStructFieldRef("five").getFieldObjectInspector();
    assertEquals(Timestamp.valueOf("2013-03-27 23:18:40.0"), jstOi.getPrimitiveJavaObject(result.get("five")));
  }
View Full Code Here

  @Test
  public void testTimestampDeSerializeWithNanoseconds() throws Exception {
    // Test that timestamp object can be deserialized
    Writable w = new Text("{\"one\":true,\"five\":\"2013-03-27 23:18:40.123456\"}");

    JSONObject result = (JSONObject) instance.deserialize(w);
   
    StructObjectInspector soi = (StructObjectInspector) instance.getObjectInspector();
   
    JavaStringTimestampObjectInspector jstOi = (JavaStringTimestampObjectInspector)
            soi.getStructFieldRef("five").getFieldObjectInspector();
    assertEquals( Timestamp.valueOf("2013-03-27 23:18:40.123456"),  jstOi.getPrimitiveJavaObject(result.get("five")));
  }
View Full Code Here

   @Test
  public void testTimestampDeSerializeNumericTimestamp() throws Exception {
    // Test that timestamp object can be deserialized
    Writable w = new Text("{\"one\":true,\"five\":1367801925}");

    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.0" ),
            jstOi.getPrimitiveJavaObject(result.get("five"))   );
  }
View Full Code Here

TOP

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

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.