4 Replies Latest reply on Mar 2, 2010 6:14 AM by galder.zamarreno

    Need to use non serializable keys

    sannegrinovero

      Hello,

      one of my current requirements is to store non serializable objects in Infinispan, and use non serializable objects as keys; these classes could have been marked Serializable but they aren't and that's out of my control.

      As I'm using invalidation clustering mode, I assume my problem is only with the keys.

       

      I was expecting that using JBossMarshaller this wouldn't be an issue, but I get errors like

      Caused by: org.infinispan.marshall.NotSerializableException:

      Can I configure externalizers / marshallers for my non serializable types? I can't change the source of classes I use as keys, so it's not possible to just declare them Serializable.

      It would be amazing if I could instruct River to just marshall objects even if they wheren't marked Serializable, is that not an option?

       

      org.infinispan.marshall.TestObjectStreamMarshaller is having an interesting comment:

      A dummy marshaller impl that uses JBoss Marshalling object streams as they do not require that the objects being
      serialized/deserialized implement Serializable.

      Does it mean I could use that?

        • 1. Re: Need to use non serializable keys
          manik

          sannegrinovero wrote:

          org.infinispan.marshall.TestObjectStreamMarshaller is having an interesting comment:

          A dummy marshaller impl that uses JBoss Marshalling object streams as they do not require that the objects being
          serialized/deserialized implement Serializable.

          Does it mean I could use that?

          Sorry to be the bearer of bad news, the comment on the TestObjectStreamMarshaller is incorrect.    That should read "A dummy .... object streams as they do require that ... "

           

          The TestObjectStreamMarshaller uses XStream to encode objects.  It's slow, but it does work.  Perhaps you could use a similar strategy?  E.g.,

           

          your key -> XStream -> a String which you can use with Infinispan

           

          I'll let Galder comment on the feasibility of exposing JBoss Marshalling externalizers as public API.

          1 of 1 people found this helpful
          • 2. Re: Need to use non serializable keys
            galder.zamarreno
            I've added an FAQ entry to http://community.jboss.org/docs/DOC-13439 where we explain what we currently support wrt Non-Serializable objects. Sanne, as you can see, we don't expect to expose the possibility of clients providing their own Externalizer implementations until Infinispan 4.1.
            1 of 1 people found this helpful
            • 3. Re: Need to use non serializable keys
              sannegrinovero

              thanks for the detailed answers; I would need this before any date a 4.1 release could be estimated at

               

              XStream would be fine as a general purpose solution but I'd avoid making it slow, and it wouldn't be easy to replace the keys with 1-1 value objects, too many cases: I can barely intercept the current Map usage and inject an Infinispan Map;

               

              I'll try to extend VersionAwareMarshaller to use a custom org.infinispan.marshall.jboss.JBossMarshaller where I could hardcode my configuration; you know if there is such an option to not verify if it's serializable and automagically use an alternative strategy? All my cases are simple value objects, like a couple of Strings, a String and an int, two longs... it would have been trivial to just mark them Serializable.

              • 4. Re: Need to use non serializable keys
                galder.zamarreno


                sannegrinovero wrote:

                 

                ...

                I'll try to extend VersionAwareMarshaller to use a custom org.infinispan.marshall.jboss.JBossMarshaller where I could hardcode my configuration; you know if there is such an option to not verify if it's serializable and automagically use an alternative strategy? All my cases are simple value objects, like a couple of Strings, a String and an int, two longs... it would have been trivial to just mark them Serializable.

                 

                Serializable verification is done by JBoss Marshaller and not Infinispan. Using a custom JBossMarshaller is probably your only option. In that class, you'd need to use a different org.infinispan.marshall.jboss.ConstantObjectTable to the one used by Infinispan so that it contains the Externalizer link between your class and the Externalizer that it uses. This is a big hack though but currently the only way u can get around this.