Giter VIP home page Giter VIP logo

grails-plugin-converters's Introduction

Grails Converters

This is the Converters plugin that has been part of Grails core up until version 3.3 and now is a standalone plugin.

Users of Grails 3.3.x and above should use this plugin.

Installation

Simply add the dependency to your build.gradle file:

implementation "org.grails.plugins:converters"

grails-plugin-converters's People

Contributors

afsdevguy avatar aulea avatar bobbywarner avatar burtbeckwith avatar davydotcom avatar dellermann avatar dependabot[bot] avatar graemerocher avatar guillermocalvo avatar houbie avatar humberthardy avatar jameskleeh avatar jwagenleitner avatar kgeis avatar ldaley avatar lhotari avatar matrei avatar mattstiner avatar memorydoor avatar musketyr avatar renovate[bot] avatar sbearcsiro avatar sdelamo avatar wololock avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grails-plugin-converters's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/gradle.yml
  • actions/checkout v4
  • gradle/wrapper-validation-action v2
  • actions/setup-java v4
  • gradle/actions v3
  • gradle/actions v3
.github/workflows/release-notes.yml
  • actions/checkout v4
  • release-drafter/release-drafter v5
  • ncipollo/release-action v1
.github/workflows/release.yml
  • actions/checkout v4
  • gradle/wrapper-validation-action v2
  • actions/setup-java v4
  • gradle/actions v3
gradle
gradle.properties
  • org.grails:grails-gradle-plugin 5.3.1
  • org.apache.commons:commons-lang3 3.14.0
  • org.codehaus.groovy:groovy-xml 3.0.21
  • org.grails:grails-datastore-gorm 7.3.4
  • javax.servlet:javax.servlet-api 4.0.1
  • org.springframework:spring-context 5.3.32
  • org.spockframework:spock-core 2.3-groovy-3.0
settings.gradle
  • com.gradle.enterprise 3.16.2
  • com.gradle.common-custom-user-data-gradle-plugin 1.13
build.gradle
  • io.github.gradle-nexus:publish-plugin 1.3.0
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 7.2

  • Check this box to trigger a request for Renovate to run again on this repository

Converters plugin, Custom marshaller, and RestBuilder break JSON rendering

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a project with the converters plugin
  2. Register custom marshallers via JSON.registerObjectMarshaller in BootStrap.groovy
  3. Somewhere in code call new RestBuilder()
  4. Attempt to render a ValidationErrors object

Expected Behaviour

The ValidationErrors object is rendered

Actual Behaviour

A ConverterException is thrown, caused by an IllegalAccessException.

org.grails.web.converters.exceptions.ConverterException: Error converting Bean with class org.springframework.beans.GenericTypeAwarePropertyDescriptor
java.lang.RuntimeException: org.grails.web.converters.exceptions.ConverterException: Error converting Bean with class org.springframework.beans.GenericTypeAwarePropertyDescriptor
	at org.grails.web.converters.AbstractConverter.toString(AbstractConverter.java:120)
	at rest.builder.experiment.FooSpec.init rest builder #initRestBuilder does not poison JSON rendering(FooSpec.groovy:38)
Caused by: org.grails.web.converters.exceptions.ConverterException: Error converting Bean with class org.springframework.beans.GenericTypeAwarePropertyDescriptor
	at org.grails.web.converters.marshaller.json.GenericJavaBeanMarshaller.marshalObject(GenericJavaBeanMarshaller.java:84)
	at org.grails.web.converters.marshaller.json.GenericJavaBeanMarshaller.marshalObject(GenericJavaBeanMarshaller.java:39)
	at grails.converters.JSON.value(JSON.java:184)
	at grails.converters.JSON.convertAnother(JSON.java:144)
	at org.grails.web.converters.marshaller.json.ArrayMarshaller.marshalObject(ArrayMarshaller.java:41)
	at org.grails.web.converters.marshaller.json.ArrayMarshaller.marshalObject(ArrayMarshaller.java:30)
	at grails.converters.JSON.value(JSON.java:184)
	at grails.converters.JSON.convertAnother(JSON.java:144)
	at org.grails.web.converters.marshaller.json.GenericJavaBeanMarshaller.marshalObject(GenericJavaBeanMarshaller.java:66)
	at org.grails.web.converters.marshaller.json.GenericJavaBeanMarshaller.marshalObject(GenericJavaBeanMarshaller.java:39)
	at grails.converters.JSON.value(JSON.java:184)
	at grails.converters.JSON.convertAnother(JSON.java:144)
	at org.grails.web.converters.marshaller.json.GroovyBeanMarshaller.marshalObject(GroovyBeanMarshaller.java:67)
	at org.grails.web.converters.marshaller.json.GroovyBeanMarshaller.marshalObject(GroovyBeanMarshaller.java:39)
	at grails.converters.JSON.value(JSON.java:184)
	at grails.converters.JSON.render(JSON.java:119)
	at org.grails.web.converters.AbstractConverter.toString(AbstractConverter.java:118)
	... 1 more
Caused by: java.lang.IllegalAccessException: Class org.grails.web.converters.marshaller.json.GenericJavaBeanMarshaller can not access a member of class org.springframework.beans.GenericTypeAwarePropertyDescriptor with modifiers "public"
	at org.grails.web.converters.marshaller.json.GenericJavaBeanMarshaller.marshalObject(GenericJavaBeanMarshaller.java:64)
	... 17 more

Environment Information

  • Operating System: Fedora 28 Workstation
  • GORM Version: N/A (but 6.1.10.RELEASE)
  • Grails Version (if using Grails): 3.3.8
  • JDK Version: OpenJDK Runtime Environment (build 1.8.0_181-b15)

Example Application

Additional Notes

Related issues:

The workaround listed grails/grails-data-mapping#864 seems to mitigate this issue.

Also calling convertersConfigurationInitializer.initialize() again right after registering the custom converters also appears to mitigate the issue, but I'm not sure if there are other side-effects.

JSON writer doesn't change its mode in maps and fails

I migrated from Grails 2 to Grails 3.3.0.M2 (with grails-plugin-converters 3.3.0.M2), and this code fails:

JSON.use("default") {
                converter = object as JSON
}

Debugging in IntelliJ, I noted that this part is not working:

    public JSONWriter object() {
        if (this.mode == INIT) {
            this.mode = OBJECT;
        }
        if (this.mode == OBJECT || this.mode == ARRAY) {
            this.append("{");
            this.push(KEY);
            this.comma = false;
            return this;
        }
        throw new JSONException("Misplaced object: expected mode of INIT, OBJECT or ARRAY but was " + this.mode);

    }

This is because the push method does not really change the mode of the JSON Writter, so maps in JSON fails. It puts the correct value in the stack attribute, but the mode continues to be ARRAY, causing type mismatch.

So this part of the code (endObject method) fails:

                    if(isMap) {
                        writer.object(); writer.endObject();
                    }

I'll try to reproduce this error in a smaller project. Thanks in advance.

Error converting Bean with class org.grails.validation.ConstrainedDelegate

Hi,
I'm having a issue with Grails 3.3.9:
compile 'org.grails.plugins:converters:3.3.1' // Provides JSON and XML converters
In a gsp file I'd like to use someMap as JSON. But eventually I get this error:

Caused by: org.grails.web.converters.exceptions.ConverterException: Error converting Bean with class org.grails.validation.ConstrainedDelegate
	at org.grails.web.converters.marshaller.json.GroovyBeanMarshaller.marshalObject(GroovyBeanMarshaller.java:85)
	at org.grails.web.converters.marshaller.json.GroovyBeanMarshaller.marshalObject(GroovyBeanMarshaller.java:39)
	at grails.converters.JSON.value(JSON.java:184)
	at grails.converters.JSON.convertAnother(JSON.java:144)
	at org.grails.web.converters.marshaller.json.MapMarshaller.marshalObject(MapMarshaller.java:45)
	at org.grails.web.converters.marshaller.json.MapMarshaller.marshalObject(MapMarshaller.java:30)
	at grails.converters.JSON.value(JSON.java:184)
	at grails.converters.JSON.convertAnother(JSON.java:144)
	at org.grails.web.converters.marshaller.json.MapMarshaller.marshalObject(MapMarshaller.java:45)
	at org.grails.web.converters.marshaller.json.MapMarshaller.marshalObject(MapMarshaller.java:30)
	at grails.converters.JSON.value(JSON.java:184)
	at grails.converters.JSON.render(JSON.java:119)
	at org.grails.web.converters.AbstractConverter.writeTo(AbstractConverter.java:110)
	at org.grails.buffer.GrailsPrintWriter.writeWritable(GrailsPrintWriter.java:568)
	at org.grails.buffer.GrailsPrintWriter.print(GrailsPrintWriter.java:576)
	at sun.reflect.GeneratedMethodAccessor892.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1427)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:169)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
	at C__repo_grails_app_views_desktop__pass_model_to_js_desktop_inc_gsp.run(C__repo_grails_app_views_desktop__pass_model_to_js_desktop_inc_gsp:39)

The map I'm trying to convert looks like this

 itemsPerPage=20,
 isTablet=false,
 disableOption=[],
 enableOption=[],
 locationOnlyGiven=true,
 altRadius=35000,
 constraints=de.company.tb.input.SearchParams$__clinit__closure3@3b854469,
 ajaxSearch=false,
 stype=S,
 offset=0,
 f_ot=[],
 validRegionId=false,
 nationalSearch=true,
 regionSearch=false,
 constraintsMap={kw=org.grails.validation.ConstrainedDelegate@14464116,
 adkw=org.grails.validation.ConstrainedDelegate@6620e89f,
 kwToShow=org.grails.validation.ConstrainedDelegate@2ab948b9,
 br=org.grails.validation.ConstrainedDelegate@3b0ef78b,
 ci=org.grails.validation.ConstrainedDelegate@1de65f0d,
 ci_list=org.grails.validation.ConstrainedDelegate@7ce3283e,
 ci_pc=org.grails.validation.ConstrainedDelegate@1c7f5b9b,
 cidistrict=org.grails.validation.ConstrainedDelegate@50014530,
 ciid=org.grails.validation.ConstrainedDelegate@7f30760a,
 ciquarter=org.grails.validation.ConstrainedDelegate@1af7130a,
 rzId=org.grails.validation.ConstrainedDelegate@7cb2204c,
 fn=org.grails.validation.ConstrainedDelegate@2640c22f,
 kgs=org.grails.validation.ConstrainedDelegate@5abc70cb,
 lat=org.grails.validation.ConstrainedDelegate@78f147d5,
 lon=org.grails.validation.ConstrainedDelegate@15aca8c7,
 phone=org.grails.validation.ConstrainedDelegate@355d41e7,
 rgid=org.grails.validation.ConstrainedDelegate@c5e45af,
 radius=org.grails.validation.ConstrainedDelegate@7ee3741e,
 stype=org.grails.validation.ConstrainedDelegate@e791195,
 pc=org.grails.validation.ConstrainedDelegate@51742bc4,
 ac=org.grails.validation.ConstrainedDelegate@2f797f78,
 altCx=org.grails.validation.ConstrainedDelegate@4adfad0d,
 altCy=org.grails.validation.ConstrainedDelegate@c6ce87a,
 altRadius=org.grails.validation.ConstrainedDelegate@7c36c838,
 street=org.grails.validation.ConstrainedDelegate@18d0fa79,
 houseno=org.grails.validation.ConstrainedDelegate@2fd08bab,
 address=org.grails.validation.ConstrainedDelegate@44948913,
 biscope=org.grails.validation.ConstrainedDelegate@e29eeb1,
 topicCategories=org.grails.validation.ConstrainedDelegate@11b5de3f,
 enableOption=org.grails.validation.ConstrainedDelegate@3a139271,
 disableOption=org.grails.validation.ConstrainedDelegate@5aaf4831,
 at=org.grails.validation.ConstrainedDelegate@1bb269b3,
 category=org.grails.validation.ConstrainedDelegate@24c918dc,
 orderby=org.grails.validation.ConstrainedDelegate@26f962e,
 page=org.grails.validation.ConstrainedDelegate@2221a892,
 seoWhat=org.grails.validation.ConstrainedDelegate@2ad6a294,
 seoWhere=org.grails.validation.ConstrainedDelegate@463550ea,
 cityToShow=org.grails.validation.ConstrainedDelegate@381570e4,
 subCityToShow=org.grails.validation.ConstrainedDelegate@175f2a4c,
 f_ot=org.grails.validation.ConstrainedDelegate@802e831,
 f_vkw=org.grails.validation.ConstrainedDelegate@64dc4bdb,
 f_ra=org.grails.validation.ConstrainedDelegate@77dd95f4,
 f_ap=org.grails.validation.ConstrainedDelegate@193edc09,
 country=org.grails.validation.ConstrainedDelegate@6e2ec7f,
 countryFrom=org.grails.validation.ConstrainedDelegate@66fdeb,
 countryTo=org.grails.validation.ConstrainedDelegate@1b8fba26,
 countrycode=org.grails.validation.ConstrainedDelegate@743ee3ca,
 fuelType=org.grails.validation.ConstrainedDelegate@65ae6826,
 internationalCity=org.grails.validation.ConstrainedDelegate@521058dd,
 internationalCitycode=org.grails.validation.ConstrainedDelegate@34a89633,
 itemsPerPage=org.grails.validation.ConstrainedDelegate@378b03df,
 offset=org.grails.validation.ConstrainedDelegate@21f2b250,
 ss_le=org.grails.validation.ConstrainedDelegate@7174c003,
 ss_sd=org.grails.validation.ConstrainedDelegate@11dc910,
 ss_hc=org.grails.validation.ConstrainedDelegate@6ee7b717,
 ss_lc=org.grails.validation.ConstrainedDelegate@5ab3f8a9,
 ajaxSearch=org.grails.validation.ConstrainedDelegate@d904f24,
 isTablet=org.grails.validation.ConstrainedDelegate@62aa42cf,
 validRegionId=org.grails.validation.ConstrainedDelegate@31260e82,
 isMobile=org.grails.validation.ConstrainedDelegate@7415cebf,
 filterCount=org.grails.validation.ConstrainedDelegate@7bf34676,
 na=org.grails.validation.ConstrainedDelegate@4bffcffd},
 isMobile=false,
 f_vkw=[],
 filterCount=0,
 at=[],
 errors=grails.validation.ValidationErrors: 0 errors,
 topicCategories=[]}```

What could cause that problem?

Error creating bean with name 'gspTagLibraryLookup': ... No signature of method: static ... isConverterClass() is applicable for argument types: ... [class java.lang.Boolean]

I have a grails 4.0 app that compiles fine with gradle but that fails when I deploy it on tomcat. I get plenty of BeanCreationExceptions that allows go back to a problem with isConverterClass (see below).

 nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gspTagLibraryLookup': Invocation of init method failed; nested exception is groovy.lang.MissingMethodException: No signature of method: static org.grails.web.converters.ConverterUtil.isConverterClass() is applicable for argument types: (Class) values: [class java.lang.Boolean]

I am quite new to grails and don't even know if this plugin is related to it. Any ideas?

JSON.parse() just greps the first json object in given source-string and returns.

See https://github.com/grails-plugins/grails-plugin-converters/blob/master/src/main/groovy/grails/converters/JSON.java#L249
and final Object value = new JSONTokener(source).nextValue();

Eg:

        def s = '{"foo":"bar"}{"baz":true}'
        def json = JSON.parse(s)
        json.toString() == '{"foo":"bar"}'

I find this behavior confusing, i was expecting rather a ConverterException than a silent ignore.

A situation where this can get nasty, is in integration specs when you do something like json = JSON.parse(controller.response.contentAsString as String) and in the related controller, more then one response was rendered like render(contentType: 'application/json', text: someJson.toString()) (by accident, eg missing return after render)

Using a closure object marshaller which returns null results in out of sequence exceptions.

I'd like to handle optionals via marshalling:

    JSON.registerObjectMarshaller(Optional) { Optional optional ->
         if (optional.present)
             return optional.get()
         else
             return null
    }

    assert (["Test": Optional.empty()] as JSON).toString(false) == '{"Test":null}' // throws out of sequence exception.

It appears to fail because the ClosureObjectMarshaller doesn't write a null value when the closure returns a null.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.