test_class.file: cosmic-core/server/src/test/java/com/cloud/api/ApiSerializerHelperTest.java
test_class.identifier: ApiSerializerHelperTest
test_case.body: @Test
      public void testFromSerializedStringSimpleExceptionResponseWithName() {
          final String string = "com.cloud.api.response.ExceptionResponse/exception/{\"errorcode\":530," +
                  "\"errortext\":\"CloudRuntimeException: A simple runtime exception\"}";
          final Object object = ApiSerializerHelper.fromSerializedString(string);
  
          assertNotNull(object);
          assertEquals(ExceptionResponse.class, object.getClass());
  
          final ExceptionResponse response = (ExceptionResponse) object;
          assertEquals("exception", response.getObjectName());
          assertEquals(530L, (long) response.getErrorCode());
          assertEquals("CloudRuntimeException: A simple runtime exception", response.getErrorText());
      }
test_case.class_method_signature: ApiSerializerHelperTest.testFromSerializedStringSimpleExceptionResponseWithName()
test_case.full_signature: @Test public void testFromSerializedStringSimpleExceptionResponseWithName()
test_case.identifier: testFromSerializedStringSimpleExceptionResponseWithName
test_case.invocations: fromSerializedString assertNotNull assertEquals getClass assertEquals getObjectName assertEquals getErrorCode assertEquals getErrorText
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testFromSerializedStringSimpleExceptionResponseWithName()
focal_class.declarator: s_logger = LoggerFactory.getLogger(ApiSerializerHelper.class.getName())
focal_class.modifier: public static final
focal_class.original_string: public static final Logger s_logger = LoggerFactory.getLogger(ApiSerializerHelper.class.getName());
focal_class.type: Logger
focal_class.var_name: s_logger
focal_class.declarator: SEPARATOR = '/'
focal_class.modifier: private static final
focal_class.original_string: private static final char SEPARATOR = '/';
focal_class.type: char
focal_class.var_name: SEPARATOR
focal_class.declarator: JSON_OBJECT_START = '{'
focal_class.modifier: private static final
focal_class.original_string: private static final char JSON_OBJECT_START = '{';
focal_class.type: char
focal_class.var_name: JSON_OBJECT_START
focal_class.file: cosmic-core/server/src/main/java/com/cloud/api/ApiSerializerHelper.java
focal_class.identifier: ApiSerializerHelper
focal_class.class_method_signature: ApiSerializerHelper.toSerializedString(final Object object)
focal_class.full_signature: public static String toSerializedString(final Object object)
focal_class.identifier: toSerializedString
focal_class.modifiers: public static
focal_class.parameters: (final Object object)
focal_class.return: String
focal_class.signature: String toSerializedString(final Object object)
focal_class.class_method_signature: ApiSerializerHelper.fromSerializedString(final String string)
focal_class.full_signature: public static Object fromSerializedString(final String string)
focal_class.identifier: fromSerializedString
focal_class.modifiers: public static
focal_class.parameters: (final String string)
focal_class.return: Object
focal_class.signature: Object fromSerializedString(final String string)
focal_method.body: public static Object fromSerializedString(final String string) {
          if (string == null || string.trim().isEmpty()) {
              return null;
          }
  
          try {
              final int classNameLimit = string.indexOf(SEPARATOR);
              if (classNameLimit == -1) {
                  return null;
              }
  
              final String className = string.substring(0, classNameLimit);
              final String afterClassName = string.substring(classNameLimit + 1 , string.length());
  
              final Class<?> clazz;
              try {
                  clazz = Class.forName(className);
              } catch (final ClassNotFoundException e) {
                  return null;
              }
  
              final Gson gson = ApiGsonHelper.getBuilder().create();
  
              final int jsonObjectPosition = afterClassName.indexOf(JSON_OBJECT_START);
              if (jsonObjectPosition == -1) {
                  return null;
              }
              if (jsonObjectPosition == 0) {
                  return gson.fromJson(afterClassName, clazz);
              }
  
              final String objectName = afterClassName.substring(0, jsonObjectPosition - 1);
              final String content = afterClassName.substring(jsonObjectPosition, afterClassName.length());
              final Object object = gson.fromJson(content, clazz);
              if (object instanceof ResponseObject) {
                  final ResponseObject responseObject = (ResponseObject) object;
                  responseObject.setObjectName(objectName);
              }
  
              return object;
          } catch (final RuntimeException e) {
              s_logger.error("Caught runtime exception when deserializing on: " + string);
              throw e;
          }
      }
focal_method.class_method_signature: ApiSerializerHelper.fromSerializedString(final String string)
focal_method.full_signature: public static Object fromSerializedString(final String string)
focal_method.identifier: fromSerializedString
focal_method.invocations: isEmpty trim indexOf substring substring length forName create getBuilder indexOf fromJson substring substring length fromJson setObjectName error
focal_method.modifiers: public static
focal_method.parameters: (final String string)
focal_method.return: Object
focal_method.signature: Object fromSerializedString(final String string)