groovy

Handle Null Attributes in MarkupBuilder

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Trivial Trivial
  • Resolution: Fixed
  • Affects Version/s: 1.0
  • Fix Version/s: 1.1-rc-1
  • Component/s: XML Processing
  • Labels:
    None
  • Number of attachments :
    0

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) {

}
}
}

Activity

Hide
Paul King added a comment -

Should be fixed in HEAD

Show
Paul King added a comment - Should be fixed in HEAD
Hide
Paul King added a comment -

No further feedback, assuming fixed

Show
Paul King added a comment - No further feedback, assuming fixed
Hide
Paul King added a comment -

Now that omitting attributes is configurable after GROOVY-1684 has been fixed, I have changed the default behavior of handling null attributes to be the same as StreamingMarkupBuilder. Please set omitNullAttributes to true if you don't want them to appear in your markup.

Show
Paul King added a comment - Now that omitting attributes is configurable after GROOVY-1684 has been fixed, I have changed the default behavior of handling null attributes to be the same as StreamingMarkupBuilder. Please set omitNullAttributes to true if you don't want them to appear in your markup.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: