Skip to content

Commit

Permalink
GRAILS-10979 - Fix support for binding to a collection of enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Scott Brown committed Jan 14, 2014
1 parent e914c1e commit 2492b59
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Expand Up @@ -318,6 +318,9 @@ class SimpleDataBinder implements DataBinder {
indexedInstance = genericType.newInstance()
bind indexedInstance, val, listener
addElementToCollectionAt obj, propName, collectionInstance, index, indexedInstance
} else if(genericType.isEnum() && val instanceof CharSequence) {
def enumValue = convertStringToEnum(genericType, val.toString())
addElementToCollectionAt obj, propName, collectionInstance, index, enumValue
}
} else {
addElementToCollectionAt obj, propName, collectionInstance, index, val
Expand Down
@@ -0,0 +1,30 @@
package org.grails.databinding

import spock.lang.Issue
import spock.lang.Specification

class SimpleDataBinderEnumBindingSpec extends Specification {
@Issue('GRAILS-10979')
void 'Test binding to a List of enum'() {
given:
def binder = new SimpleDataBinder()
def holder = new HatSizeHolder()

when:
binder.bind holder, ['sizes[0]': 'LARGE', 'sizes[1]': 'SMALL'] as SimpleMapDataBindingSource

then:
holder.sizes?.size() == 2
holder.sizes[0] == HatSize.LARGE
holder.sizes[1] == HatSize.SMALL
}

}

enum HatSize {
SMALL, MEDIUM, LARGE
}

class HatSizeHolder {
List<HatSize> sizes
}

0 comments on commit 2492b59

Please sign in to comment.