Skip to content

Commit

Permalink
deserialize enum from object representation
Browse files Browse the repository at this point in the history
  • Loading branch information
pootow committed Jul 17, 2014
1 parent 85be5f7 commit 17ae698
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ServiceFacadeGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.nofdev.servicefacade.grails.PagedResultListCategory

class ServiceFacadeGrailsPlugin {
// the plugin version
def version = "3.2.3"
def version = "4.2.3"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.1 > *"
// resources that are excluded from plugin packaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,19 @@ class SimpleJSONDeserializer {

def handelJSONPart(Object part, Type type) {
log.trace("handelJSONPart:<$part> of type:<$type>")
if (part instanceof JSONElement) {
log.trace("instance of JSONElement")
handelJSONElement(part as JSONElement, type)
} else if (part instanceof JSONObject.Null) {
log.trace('element is JSONObject.Null')
null
} else if (type.enum) {
if (type.enum) {
log.trace('element is an instance of enum')
if (part instanceof String) {
log.trace('enum is String representation')
if (((String)part).trim() == "")
return null
type.valueOf(part)
}
else
} else if(part instanceof JSONObject) {
log.trace('enum is Object representation, process it with name property')
type.valueOf(part.name)
} else {
throw new NotSupportedException('Cannot convert to enum except String value!')
}
} else if (type == DateTime) {
log.trace('element is jodatime.DateTime')
if (part instanceof String) {
Expand All @@ -58,6 +56,12 @@ class SimpleJSONDeserializer {
}
else
throw new NotSupportedException('Cannot convert to jodatime.DateTime except String value!')
} else if (part instanceof JSONElement) {
log.trace("instance of JSONElement")
handelJSONElement(part as JSONElement, type)
} else if (part instanceof JSONObject.Null) {
log.trace('element is JSONObject.Null')
null
} else {
log.trace("return $part")
part
Expand Down

0 comments on commit 17ae698

Please sign in to comment.