Choose deep or shallow JSON serialization in Grails

Is there a way to easily indicate whether to convert the object as JSON in deep or shallow mode? I know that you can configure the grails.converters.JSON utility in the Config.groovy file by specifying something like the following:

grails.converters.json.default.deep = true 

but when I convert certain objects, I don’t want to convert deeply.

I also saw that someone recommended using JSON.use ("deep"), but I get the following error:

 Error 2012-03-04 00:39:13,673 ["http-bio-8080"-exec-1] ERROR errors.GrailsExceptionResolver - IllegalAccessException occurred when processing request: [GET] /Quaffic/home/json Class org.codehaus.groovy.grails.web.converters.marshaller.json.GenericJavaBeanMarshaller can not access a member of class org.joda.time.tz.DateTimeZoneBuilder$PrecalculatedZone with modifiers "public". Stacktrace follows: Message: Class org.codehaus.groovy.grails.web.converters.marshaller.json.GenericJavaBeanMarshaller can not access a member of class org.joda.time.tz.DateTimeZoneBuilder$PrecalculatedZone with modifiers "public" Line | Method ->> 198 | value in grails.converters.JSON 

It seems like it might be a joda.time error, but this does not happen when I just use the simple Config.groovy method. Kind of confusing ...

Any help would be great!

+4
source share
1 answer

My solution was to not rely on the deep / shallow json generation. I created a map, inserted elements and serialized it. This is probably not the best practice, but it is doing its job.

+6
source

Source: https://habr.com/ru/post/1399615/


All Articles