Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3337

ObjectGraphBuilder should support multiple associations for the same class

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.7
    • 1.6.3, 1.7-beta-1
    • None
    • None
    • Patch

    Description

      It doesn't seem possible to do something like this:

      class Company {
      String name
      Employee md
      Employee cio
      }

      class Employee {
      String name
      }

      def builder = new ObjectGraphBuilder()

      def company = builder.company( name: 'ACME' )

      { md( name: 'Billy Bob') cio( name: 'Joey Johns') }

      }

      Where the same class is associated mutliple times by different fields.

      Why not use the field name as the builder nodes and have ObjectGraphBuilder determine the class using reflection?
      I have attached a patch that does this. Unfortunately I had trouble building groovy-core so I wasn't able to run the ObjectGraphBuilder or add extra tests.

      Anyway, I just wanted to see if anyone thought this was a good idea, then maybe I can finish it off.

      This patch slightly changes the meaning of the classNameResolver - it would only apply to "root" classes. Maybe it should be renamed and the docs updated.

      Attachments

        1. ObjectGraphBuilderReflection.patch
          11 kB
          David Donn
        2. ObjectGraphBuilder.patch
          4 kB
          David Donn

        Activity

          People

            aalmiray Andres Almiray
            dusura David Donn
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: