Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-555

Incorrect object type received in BSONObject encoding hook (Transformer) when multiple transformers found

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Major - P3 Major - P3
    • None
    • None
    • BSON
    • None
    • Minor Change

    Description

      When multiple encoding hooks are found for a class in BSONObject, they are applied linearly:

      BSON.java line 202 to 205:
      List<Transformer> l = _encodingHooks.get( o.getClass() );
      if ( l != null )
        for ( Transformer t : l )
          o = t.transform( o );

      If the first transformer found transforms from C to T and the second from C to R (both were registered as encoding hooks for class C or one of its superclasses):
      1. The first transformer transforms o (of type C) to o' of type T
      2. The second transformer, programmed to transform things of type C receives an object of type T, which is potentially unrelated to C. So, we receive an object of an unexpected type.

      Solution would be to apply the first transformer (getting o' of type T) and then looking for encoding hooks for class T and so on, until no encoding hooks are found.

      Apart from that, if I have a class C1 that extends C2 and I have encoding hooks for both (EH1 and EH2), when given an object of type C2 to DBObject, EH2 should be applied, not EH1, since C2 is more specific than C1. Currently, it applies both (and this is how I found what I explained earlier).

      Attachments

        Activity

          People

            Unassigned Unassigned
            jordipradel Jordi Pradel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: