Uploaded image for project: 'Spring Modules'
  1. Spring Modules
  2. MOD-341

Forced Serialization Strategy using XStreamSerializableFactory fails as deserialization was not implemented.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.8
    • Fix Version/s: 0.9
    • Component/s: CACHE
    • Labels:
      None

      Description

      Once an object that does not implement Serializable has been stored in the cache, it could not
      be retrieved as the existing getFromCache method returned the Wrapper created by the
      serializableFactory.makeSerializableIfNecessary method.

      Inserting
      cachedObject = deserializeIfNecessary(cachedObject);
      after getting the object from the cache reverses the (XStream) serialization (implementation see below).

      It is also necessary to implement XStreamSerilizableFactory's getOriginalValue() method to actually reconvert
      the generated xml into the serialized object.

      ----------------------------------
      MODIFY class AbstractCacheProviderFacade (1)
      /**

      • @see CacheProviderFacade#getFromCache(Serializable, CachingModel)
        */
        public final Object getFromCache(Serializable key, CachingModel model)
        throws CacheException {

      if (logger.isDebugEnabled())

      { logger.debug("Attempt to retrieve a cache entry using key <" + StringUtils.quoteIfString(key) + "> and cache model <" + model + ">"); }

      Object cachedObject = null;

      try {
      if (model != null)

      { cachedObject = onGetFromCache(key, model); }

      cachedObject = deserializeIfNecessary(cachedObject);

      if (logger.isDebugEnabled())

      { logger.debug("Retrieved cache element <" + StringUtils.quoteIfString(cachedObject) + ">"); }

      } catch (CacheException exception)

      { handleCatchedException(exception); }

      return cachedObject;
      }
      -----------------------------
      INSERT class AbstractCacheProviderFacade (2)
      /**

      • Deserializes the given object if a SerializableFactory is set
      • and the object is only a wrapper.
      • Otherwise, will return the same object passed as argument.
      • @param obj
      • the object to check.
      • @return the given object as a serializable object if necessary.
      • @throws ObjectCannotBeCachedException
      • if the cache requires serializable elements, the given object
      • does not implement <code>java.io.Serializable</code> and the
      • factory of serializable objects is <code>null</code>.
      • @see #setSerializableFactory(SerializableFactory)
        */
        protected final Object deserializeIfNecessary(Object obj) {
        if (!isSerializableCacheElementRequired()) { return obj; }

      if (obj == null)

      { return obj; }

      return serializableFactory.getOriginalValue(obj);
      }
      -----------------------
      MODIFY XStreamSerializableFactory
      /**

      • @see SerializableFactory#getOriginalValue(Object)
        */
        public Object getOriginalValue(Object obj) {
        if (!(obj instanceof ObjectWrapper)) { return obj; }

      ObjectWrapper wrapper = (ObjectWrapper) obj;
      return xstream.fromXML((String) wrapper.getValue());
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              irbouho Omar Irbouh
              Reporter:
              hartmut Hartmut Obendorf
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: