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

Handle Null Attributes in MarkupBuilder

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 1.0
    • 1.1-rc-1
    • XML Processing
    • None

    Description

      Can we alter MarkupBuilder to ignore optional attributes that aren't specified (contain null values).

      Currently MarkupBuilder throws a NullPointerException if I create a node using attributes that contain a null map value. For example:

      def writer = new StringWriter()
      def builder = new MarkupBuilder(writer)

      builder.A {
      B {
      C(D: 'E', F: null) {

      }
      }
      }
      // throws NullPointerException in MarkupBuilder.createNode

      When building XML using MarkupBuilder, I find it useful to specify all attributes (required or optional) for a node in one line rather than having to implement ugly logic checks myself like follows:

      builder.A {
      B {
      def map = [:]
      if (E)

      { map['D'] = 'E' }

      if (F)

      { map['F'] = 'G' }

      C(map) {

      }
      }
      }

      Attachments

        Activity

          People

            paulk Paul King
            kcender07 Red Neck
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: