-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GSON problem: custom adapters not used #36
Comments
I'm experiencing the same problems. |
What's the diff between ApplicationContextAware and setting applicationContext in the bean definition? Maybe the issue is with ApplicationContextAware? |
I believe when going through the GroovyDefaultMethods asType calls, it just constructs the GSON object. Since it never passes through Spring and applicationContext is never set. Without access to the applicationContext, there's no hope that the gsonBuilder can get set. I think the orignal idea was that since the ArtefactEnhancer is adding the render method and since it has a proper gson object, this could work. But the variable is defined both at the class level and as the argument the closure. Since the argument to the closure is bullocks, we should be using it, but it's scoped as the variable to use. I think the fix is remove the arg from the closure in enhanceControllers(). I'll try locally and see what happens. |
ConvertersDomainTransformer seems responsible for properly creating the GSON converter, but only for Domain objects, not on Controllers. |
Is this a problem with accessing the spring context from a static context when using |
@robfletcher It's just a controller action, not a static method. |
@sergiomichels yeah, the static-ness is in the gson plugin |
@robfletcher I think that using |
hmmm I'm getting a hard time trying to reproduce this again. |
This is still an issue, I have the same problem: applicationContext is null in GSON when using
My custom DateAdapter is not used in this case. |
I made a suggestion in #35. |
This is potentially solve alb using |
For some reason GSON is failing in get the GsonBuilder from the applicationContext, this causes the class to return a new GsonBuilder() without my custom Adapters. For example:
In my case it prints "Not found bean gsonBuilder" and by consequence using
render model as GSON
fails to use my adapters.The problem goes away if I explicity declare gsonBuilder in my controller and use
render contentType: 'application/json', text: gson.toJson(model)
Maybe it's a problem with ApplicationContextAware? I can also see that applicationContext is null in GSON.
The text was updated successfully, but these errors were encountered: