private void serializeAndDeserializeObject(Object object) throws Exception {
    BufferDataOutputStream outputStream = new BufferDataOutputStream(KnownVersion.CURRENT);
    try {
      serializeObject(object, outputStream);
    } catch (IOException | NullPointerException e) {
      // some classes, such as BackupLock, are Serializable because the extend something
      // like ReentrantLock but we never serialize them & it doesn't work to try to do so
      System.out.println("Not Serializable: " + object.getClass().getName());
      return;
    } catch (Exception e) {
      /*
       * NOTE:
       * this block catches Exception instead of CacheClosedException so that modules without
       * dependency on geode-core can be tested with Analyze Serializables.
       *
       * ex: geode-membership does not depend on geode-core, so it cannot load CacheClosedException
       */
      if ("org.apache.geode.cache.CacheClosedException".equals(e.getClass().getName())) {
        System.out
            .println("I was unable to serialize " + object.getClass().getName() + " due to " + e);
        e.printStackTrace();
        return;
      }
      throw e;
    }

    Throwable thrown = catchThrowable(() -> deserializeObject(outputStream));

    assertThat(thrown)
        .withFailMessage("I was able to deserialize " + object.getClass().getName())
        .isInstanceOf(InvalidClassException.class);
  }
Prepare your serialization service for use
geode-junit/src/main/java/org/apache/geode/codeAnalysis/AnalyzeDataSerializablesTestBase.java