test_class.declarator: jsonHelper
test_class.modifier: @Autowired
      private
test_class.original_string: @Autowired
      private JsonHelper jsonHelper;
test_class.type: JsonHelper
test_class.var_name: jsonHelper
test_class.file: herd-code/herd-dao/src/test/java/org/finra/herd/dao/helper/JsonHelperTest.java
test_class.identifier: JsonHelperTest
test_class.superclass: extends AbstractDaoTest
test_case.body: @Test
      public void testGetKeyValue() throws Exception
      {
          // Create a JSON object with one key value pair.
          JSONParser jsonParser = new JSONParser();
          JSONObject jsonObject = (JSONObject) jsonParser.parse(String.format("{\"%s\" : \"%s\"}", KEY, VALUE));
  
          // Get and validate the key value.
          assertEquals(VALUE, jsonHelper.getKeyValue(jsonObject, KEY, String.class));
  
          // Try to get a value for a non-existing key.
          try
          {
              jsonHelper.getKeyValue(jsonObject, I_DO_NOT_EXIST, String.class);
              fail();
          }
          catch (IllegalArgumentException e)
          {
              assertEquals(String.format("Failed to get \"%s\" key value from JSON object.", I_DO_NOT_EXIST), e.getMessage());
          }
  
          // Try to get a value that cannot be cast to the specified class type.
          try
          {
              jsonHelper.getKeyValue(jsonObject, KEY, BigDecimal.class);
              fail();
          }
          catch (IllegalArgumentException e)
          {
              assertEquals(String.format("Failed to cast \"%s\" key value to %s.", VALUE, BigDecimal.class.getName()), e.getMessage());
          }
      }
test_case.class_method_signature: JsonHelperTest.testGetKeyValue()
test_case.full_signature: @Test public void testGetKeyValue()
test_case.identifier: testGetKeyValue
test_case.invocations: parse format assertEquals getKeyValue getKeyValue fail assertEquals format getMessage getKeyValue fail assertEquals format getName getMessage
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testGetKeyValue()
focal_class.file: herd-code/herd-dao/src/main/java/org/finra/herd/dao/helper/JsonHelper.java
focal_class.identifier: JsonHelper
focal_class.class_method_signature: JsonHelper.getKeyValue(JSONObject jsonObject, Object key, Class<T> classType)
focal_class.full_signature: public T getKeyValue(JSONObject jsonObject, Object key, Class<T> classType)
focal_class.identifier: getKeyValue
focal_class.modifiers: public
focal_class.parameters: (JSONObject jsonObject, Object key, Class<T> classType)
focal_class.return: T
focal_class.signature: T getKeyValue(JSONObject jsonObject, Object key, Class<T> classType)
focal_class.class_method_signature: JsonHelper.objectToJson(Object object)
focal_class.full_signature: public String objectToJson(Object object)
focal_class.identifier: objectToJson
focal_class.modifiers: public
focal_class.parameters: (Object object)
focal_class.return: String
focal_class.signature: String objectToJson(Object object)
focal_class.class_method_signature: JsonHelper.unmarshallJsonToListOfObjects(Class<T> classType, String jsonContent)
focal_class.full_signature: public List<T> unmarshallJsonToListOfObjects(Class<T> classType, String jsonContent)
focal_class.identifier: unmarshallJsonToListOfObjects
focal_class.modifiers: public
focal_class.parameters: (Class<T> classType, String jsonContent)
focal_class.return: List<T>
focal_class.signature: List<T> unmarshallJsonToListOfObjects(Class<T> classType, String jsonContent)
focal_class.class_method_signature: JsonHelper.unmarshallJsonToObject(Class<T> classType, String jsonContent)
focal_class.full_signature: public T unmarshallJsonToObject(Class<T> classType, String jsonContent)
focal_class.identifier: unmarshallJsonToObject
focal_class.modifiers: public
focal_class.parameters: (Class<T> classType, String jsonContent)
focal_class.return: T
focal_class.signature: T unmarshallJsonToObject(Class<T> classType, String jsonContent)
focal_method.body: public <T> T getKeyValue(JSONObject jsonObject, Object key, Class<T> classType)
      {
          Object result = jsonObject.get(key);
  
          if (result == null)
          {
              throw new IllegalArgumentException(String.format("Failed to get \"%s\" key value from JSON object.", key.toString()));
          }
  
          try
          {
              return classType.cast(result);
          }
          catch (ClassCastException e)
          {
              throw new IllegalArgumentException(String.format("Failed to cast \"%s\" key value to %s.", result.toString(), classType.getName()), e);
          }
      }
focal_method.class_method_signature: JsonHelper.getKeyValue(JSONObject jsonObject, Object key, Class<T> classType)
focal_method.full_signature: public T getKeyValue(JSONObject jsonObject, Object key, Class<T> classType)
focal_method.identifier: getKeyValue
focal_method.invocations: get format toString cast format toString getName
focal_method.modifiers: public
focal_method.parameters: (JSONObject jsonObject, Object key, Class<T> classType)
focal_method.return: T
focal_method.signature: T getKeyValue(JSONObject jsonObject, Object key, Class<T> classType)