Skip to content

Commit 4472d5d

Browse files
authored
Merge pull request #15238 from jdaugherty/7.0.x
2 parents 8d3aa3e + d9e602e commit 4472d5d

File tree

6 files changed

+72
-3
lines changed

6 files changed

+72
-3
lines changed

grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/GenericJavaBeanMarshaller.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public void marshalObject(Object o, JSON json) throws ConverterException {
6161
if (!shouldInclude(includeExcludeSupport, includes, excludes, o, name)) continue;
6262

6363
if (readMethod != null && !(name.equals("metaClass")) && !(name.equals("class"))) {
64+
if (Modifier.isStatic(readMethod.getModifiers())) continue;
6465
if (readMethod.getAnnotation(PersistenceMethod.class) != null) continue;
6566
if (readMethod.getAnnotation(ControllerMethod.class) != null) continue;
6667
Object value = readMethod.invoke(o, (Object[]) null);

grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/GroovyBeanMarshaller.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public void marshalObject(Object o, JSON json) throws ConverterException {
6363
if (!shouldInclude(includeExcludeSupport, includes, excludes, o, name)) continue;
6464

6565
if (readMethod != null && !(name.equals("metaClass")) && !(name.equals("class"))) {
66+
if (Modifier.isStatic(readMethod.getModifiers())) continue;
6667
if (readMethod.getAnnotation(PersistenceMethod.class) != null) continue;
6768
if (readMethod.getAnnotation(ControllerMethod.class) != null) continue;
6869
Object value = readMethod.invoke(o, (Object[]) null);

grails-converters/src/main/groovy/org/grails/web/converters/marshaller/xml/GenericJavaBeanMarshaller.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public void marshalObject(Object o, XML xml) throws ConverterException {
4545
String name = property.getName();
4646
Method readMethod = property.getReadMethod();
4747
if (readMethod != null) {
48+
if (Modifier.isStatic(readMethod.getModifiers())) continue;
4849
Object value = readMethod.invoke(o, (Object[]) null);
4950
xml.startNode(name);
5051
xml.convertAnother(value);

grails-converters/src/main/groovy/org/grails/web/converters/marshaller/xml/GroovyBeanMarshaller.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public void marshalObject(Object o, XML xml) throws ConverterException {
6363
if (isEntity && (name.equals(GormProperties.ATTACHED) || name.equals(GormProperties.ERRORS))) continue;
6464
Method readMethod = property.getReadMethod();
6565
if (readMethod != null && !(name.equals("metaClass")) && !(name.equals("class"))) {
66+
if (Modifier.isStatic(readMethod.getModifiers())) continue;
6667
if (readMethod.getAnnotation(PersistenceMethod.class) != null) continue;
6768
if (readMethod.getAnnotation(ControllerMethod.class) != null) continue;
6869
Object value = readMethod.invoke(o, (Object[]) null);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.grails.web.converters.marshaller.json
20+
21+
import spock.lang.Specification
22+
23+
import org.springframework.context.ApplicationContext
24+
25+
import grails.converters.JSON
26+
import grails.core.DefaultGrailsApplication
27+
import grails.validation.Constrained
28+
import org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext
29+
import org.grails.datastore.mapping.model.MappingContext
30+
import org.grails.web.converters.configuration.ConvertersConfigurationInitializer
31+
32+
class StaticPropertySpec extends Specification {
33+
void initJson() {
34+
final initializer = new ConvertersConfigurationInitializer()
35+
def grailsApplication = new DefaultGrailsApplication(MyGroovyBean)
36+
grailsApplication.initialise()
37+
def mappingContext = new KeyValueMappingContext("json")
38+
grailsApplication.setApplicationContext(Stub(ApplicationContext) {
39+
getBean('grailsDomainClassMappingContext', MappingContext) >> {
40+
mappingContext
41+
}
42+
})
43+
grailsApplication.setMappingContext(mappingContext)
44+
initializer.grailsApplication = grailsApplication
45+
initializer.initialize()
46+
47+
}
48+
49+
void "static property should be excluded"() {
50+
given:
51+
initJson()
52+
53+
when:
54+
MyGroovyBean bean = new MyGroovyBean(aProperty: 'testing')
55+
56+
then:
57+
def jsonString = new JSON(bean).toString()
58+
jsonString == '{"aProperty":"testing"}'
59+
}
60+
}
61+
62+
class MyGroovyBean {
63+
static Map<String, Constrained> getConstraintsMap() {
64+
[:]
65+
}
66+
67+
String aProperty
68+
}

grails-test-suite-web/src/test/groovy/org/grails/plugins/web/rest/render/xml/DefaultXmlRendererSpec.groovy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.grails.plugins.web.rest.render.xml
2020

21-
import groovy.transform.CompileStatic
2221
import groovy.xml.XmlSlurper
2322
import grails.converters.XML
2423
import grails.core.DefaultGrailsApplication
@@ -36,7 +35,6 @@ import org.grails.web.servlet.mvc.GrailsWebRequest
3635
import org.springframework.mock.web.MockHttpServletRequest
3736
import org.springframework.mock.web.MockHttpServletResponse
3837
import org.springframework.mock.web.MockServletContext
39-
import spock.lang.PendingFeature
4038
import spock.lang.Specification
4139

4240
/**
@@ -56,7 +54,6 @@ class DefaultXmlRendererSpec extends Specification implements DomainUnitTest<Xml
5654
ConvertersConfigurationHolder.clear()
5755
}
5856

59-
@PendingFeature(reason = 'java.lang.IllegalAccessException: class org.grails.web.converters.marshaller.xml.GenericJavaBeanMarshaller cannot access a member of class org.grails.datastore.mapping.model.MappingFactory$1 with modifiers "public"')
6057
void 'Test that XML renderer writes XML to the response for a domain instance'() {
6158
when: 'A domain instance is rendered'
6259
def renderer = new DefaultXmlRenderer(XmlBook)

0 commit comments

Comments
 (0)