Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void marshalObject(Object o, JSON json) throws ConverterException {
if (!shouldInclude(includeExcludeSupport, includes, excludes, o, name)) continue;

if (readMethod != null && !(name.equals("metaClass")) && !(name.equals("class"))) {
if (Modifier.isStatic(readMethod.getModifiers())) continue;
if (readMethod.getAnnotation(PersistenceMethod.class) != null) continue;
if (readMethod.getAnnotation(ControllerMethod.class) != null) continue;
Object value = readMethod.invoke(o, (Object[]) null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void marshalObject(Object o, JSON json) throws ConverterException {
if (!shouldInclude(includeExcludeSupport, includes, excludes, o, name)) continue;

if (readMethod != null && !(name.equals("metaClass")) && !(name.equals("class"))) {
if (Modifier.isStatic(readMethod.getModifiers())) continue;
if (readMethod.getAnnotation(PersistenceMethod.class) != null) continue;
if (readMethod.getAnnotation(ControllerMethod.class) != null) continue;
Object value = readMethod.invoke(o, (Object[]) null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void marshalObject(Object o, XML xml) throws ConverterException {
String name = property.getName();
Method readMethod = property.getReadMethod();
if (readMethod != null) {
if (Modifier.isStatic(readMethod.getModifiers())) continue;
Object value = readMethod.invoke(o, (Object[]) null);
xml.startNode(name);
xml.convertAnother(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void marshalObject(Object o, XML xml) throws ConverterException {
if (isEntity && (name.equals(GormProperties.ATTACHED) || name.equals(GormProperties.ERRORS))) continue;
Method readMethod = property.getReadMethod();
if (readMethod != null && !(name.equals("metaClass")) && !(name.equals("class"))) {
if (Modifier.isStatic(readMethod.getModifiers())) continue;
if (readMethod.getAnnotation(PersistenceMethod.class) != null) continue;
if (readMethod.getAnnotation(ControllerMethod.class) != null) continue;
Object value = readMethod.invoke(o, (Object[]) null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.grails.web.converters.marshaller.json

import spock.lang.Specification

import org.springframework.context.ApplicationContext

import grails.converters.JSON
import grails.core.DefaultGrailsApplication
import grails.validation.Constrained
import org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext
import org.grails.datastore.mapping.model.MappingContext
import org.grails.web.converters.configuration.ConvertersConfigurationInitializer

class StaticPropertySpec extends Specification {
void initJson() {
final initializer = new ConvertersConfigurationInitializer()
def grailsApplication = new DefaultGrailsApplication(MyGroovyBean)
grailsApplication.initialise()
def mappingContext = new KeyValueMappingContext("json")
grailsApplication.setApplicationContext(Stub(ApplicationContext) {
getBean('grailsDomainClassMappingContext', MappingContext) >> {
mappingContext
}
})
grailsApplication.setMappingContext(mappingContext)
initializer.grailsApplication = grailsApplication
initializer.initialize()

}

void "static property should be excluded"() {
given:
initJson()

when:
MyGroovyBean bean = new MyGroovyBean(aProperty: 'testing')

then:
def jsonString = new JSON(bean).toString()
jsonString == '{"aProperty":"testing"}'
}
}

class MyGroovyBean {
static Map<String, Constrained> getConstraintsMap() {
[:]
}

String aProperty
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.grails.plugins.web.rest.render.xml

import groovy.transform.CompileStatic
import groovy.xml.XmlSlurper
import grails.converters.XML
import grails.core.DefaultGrailsApplication
Expand All @@ -36,7 +35,6 @@ import org.grails.web.servlet.mvc.GrailsWebRequest
import org.springframework.mock.web.MockHttpServletRequest
import org.springframework.mock.web.MockHttpServletResponse
import org.springframework.mock.web.MockServletContext
import spock.lang.PendingFeature
import spock.lang.Specification

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

@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"')
void 'Test that XML renderer writes XML to the response for a domain instance'() {
when: 'A domain instance is rendered'
def renderer = new DefaultXmlRenderer(XmlBook)
Expand Down
Loading