Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: tombujok/grails-core
...
head fork: tombujok/grails-core
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
4 grails-plugin-rest/src/main/groovy/grails/rest/render/hal/HalJsonRenderer.groovy
View
@@ -174,7 +174,7 @@ class HalJsonRenderer<T> extends AbstractLinkingRenderer<T> {
if (value instanceof Number) {
writer.name(propertyName).value((Number) value)
}
- else if (value instanceof CharSequence) {
+ else if (value instanceof CharSequence || value instanceof Enum) {
writer.name(propertyName).value(value.toString())
}
else {
@@ -301,7 +301,7 @@ class HalJsonRenderer<T> extends AbstractLinkingRenderer<T> {
if(value instanceof Number) {
jsonWriter.name(propertyName).value((Number)value)
}
- else if(value instanceof CharSequence) {
+ else if(value instanceof CharSequence || value instanceof Enum) {
jsonWriter.name(propertyName).value(value.toString())
}
else if(value instanceof Date) {
68 grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalJsonRendererSpec.groovy
View
@@ -16,29 +16,32 @@
package org.grails.plugins.web.rest.render.hal
+import grails.persistence.Entity
+import grails.rest.render.Renderer
import grails.rest.render.hal.HalJsonCollectionRenderer
-import groovy.transform.NotYetImplemented
-import org.springframework.core.convert.converter.Converter
-import spock.lang.Ignore
-import spock.lang.Specification
import grails.rest.render.hal.HalJsonRenderer
-import org.springframework.context.support.StaticMessageSource
-import org.grails.datastore.mapping.model.MappingContext
-import org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext
-import org.codehaus.groovy.grails.web.mapping.LinkGenerator
-import org.codehaus.groovy.grails.web.mapping.DefaultLinkGenerator
+import grails.util.GrailsWebUtil
import grails.web.CamelCaseUrlConverter
-import org.codehaus.groovy.grails.web.mapping.UrlMappingsHolder
+import groovy.transform.NotYetImplemented
+
+import javax.xml.bind.DatatypeConverter
+
+import org.codehaus.groovy.grails.web.mapping.DefaultLinkGenerator
import org.codehaus.groovy.grails.web.mapping.DefaultUrlMappingEvaluator
-import org.springframework.mock.web.MockServletContext
import org.codehaus.groovy.grails.web.mapping.DefaultUrlMappingsHolder
-import grails.persistence.Entity
-import grails.util.GrailsWebUtil
-import org.springframework.web.util.WebUtils
+import org.codehaus.groovy.grails.web.mapping.LinkGenerator
+import org.codehaus.groovy.grails.web.mapping.UrlMappingsHolder
+import org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext
+import org.grails.datastore.mapping.model.MappingContext
import org.grails.plugins.web.rest.render.ServletRenderContext
-import spock.lang.Issue
+import org.springframework.context.support.StaticMessageSource
+import org.springframework.core.convert.converter.Converter
+import org.springframework.mock.web.MockServletContext
+import org.springframework.web.util.WebUtils
-import javax.xml.bind.DatatypeConverter
+import spock.lang.Ignore
+import spock.lang.Issue
+import spock.lang.Specification
/**
*/
@@ -540,9 +543,27 @@ class HalJsonRendererSpec extends Specification{
}'''
}
-
- @Issue('GRAILS-10372')
- @Ignore
+
+ @Issue('GRAILS-10781')
+ void 'Test that the HAL renderer renders enums successfully for non domain classes'() {
+ given: 'A HAL render'
+ Renderer render = new HalJsonRenderer(Moment)
+
+ when: 'A non domain is rendered'
+ def webRequest = GrailsWebUtil.bindMockWebRequest()
+ webRequest.request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/moment/theFuture")
+ def response = webRequest.response
+ def renderContext = new ServletRenderContext(webRequest)
+ def moment = new Moment(type: Moment.Category.FUTURE)
+ renderer.render moment, renderContext
+
+ then: 'The resulting HAL is correct'
+ response.contentType == GrailsWebUtil.getContentType(HalJsonRenderer.MIME_TYPE.name, GrailsWebUtil.DEFAULT_ENCODING)
+ response.contentAsString == '''{"_links":{"self":{"href":"http://localhost/moment/theFuture","hreflang":"en","type":"application/hal+json"}},"type":"FUTURE"}'''
+
+ }
+
+ @Issue('GRAILS-10372 GRAILS-10781')
void "Test that the HAL renderer renders mixed fields (dates, enums) successfully for domains"() {
given:"A HAL renderer"
HalJsonRenderer renderer = getEventRenderer()
@@ -567,7 +588,7 @@ class HalJsonRendererSpec extends Specification{
"type": "application/hal+json"
}
},
- "date": "2013-11-08T21:12:30Z",
+ "date": "2013-11-08T19:12:30Z",
"name": "Lollapalooza",
"state": "OPEN"
}'''
@@ -720,6 +741,13 @@ class Event {
State state
}
+class Moment {
+ enum Category {
+ PAST, PRESENT, FUTURE
+ }
+ Category type
+}
+
class SimpleProduct {
String name
Integer numberInStock

No commit comments for this range

Something went wrong with that request. Please try again.