1. XStream
  2. XSTR-157

Hard to allow xstream to have a converter supporting generated classes


    • Type: Improvement Improvement
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2
    • Component/s: None
    • Labels:


      I am trying to create a converter for cglib. The initial idea was to do just like XStream is already doing for JDK dynamic proxies.

      The problem is that XStream is cheating a lot to have proxies working.

      First you need an alias to replace the class name.

      Then you need this alias to return a Dummy class that will allow the wanted converter to be called.

      After that, you need to override DefaultClassMapper to replicate this hack in DefaultClassMapper:

      if (result == null && Proxy.isProxyClass(type)) {
      result = (String) typeToNameMap.get(DynamicProxy.class);

      And finally, you need to register the converter in your new mapper because the converter needs the mapper.

      All this is not really obvious. And it's not possible to provide a generic converter since you also need a ClassMapper.

      So we really need something better. There are loads of solutions. All requiring more of less refactoring.

      I think the question should be: If I want to remove all the Dynamic proxy's hacks, what should I do?

      The solution I can think of:
      1- To pass a class name instead of a Class to canConvert. It will remove the need to have a dummy class and putting an alias will be made easy.
      2- Allow the converter to have a converter to have the mapper injected in some kind of way when we register it to XStream.
      3- Have something more powerful than aliases. Maybe have a new method on Converters that perform the lookup. If this is not efficient, be at least able to have a lookup hook where we can put code like Proxy.isProxyClass(type)

        Issue Links


          • Assignee:
            Henri Tremblay
          • Votes:
            1 Vote for this issue
            0 Start watching this issue


            • Created: