Skip to content
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

JsonIgnoreProperties not considered while converting groovy class to json #519

Closed
iWebi opened this issue Mar 31, 2014 · 11 comments
Closed
Assignees
Labels
Milestone

Comments

@iWebi
Copy link

iWebi commented Mar 31, 2014

I have a Rest resource with as groovy class as response type.
I used @JsonIgnoreProperties annotation to exclude metaClass property from groovy. But still this property is listed in swagger-ui Response Class model.
http://stackoverflow.com/questions/22763820/exclude-metaclass-properties-for-groovy-model-classes-in-swagger lists the Foo instance.

com.wordnik.swagger.converter.ModelPropertyParser class does not seem to consider the JsonIgnoreProperties annotation. Is this true? How do I make swagger consider my JsonIgnoreProperties annotation?

@fehguy
Copy link
Contributor

fehguy commented Mar 31, 2014

Can you update to 1.3.4, which was released yesterday? It should pick up
the annotation
On Mar 31, 2014 10:51 AM, "Suman Jakkula" notifications@github.com wrote:

I have a Rest resource with as groovy class as response type.
I used @JsonIgnoreProperties annotation to exclude metaClass property from
groovy. But still this property is listed in swagger-ui Response Class
model.

http://stackoverflow.com/questions/22763820/exclude-metaclass-properties-for-groovy-model-classes-in-swaggerlists the Foo instance.

com.wordnik.swagger.converter.ModelPropertyParser class does not seem to
consider the JsonIgnoreProperties annotation. Is this true? How do I make
swagger consider my JsonIgnoreProperties annotation?

Reply to this email directly or view it on GitHubhttps://github.com//issues/519
.

@iWebi
Copy link
Author

iWebi commented Mar 31, 2014

am using 1.3.4. I see below output when I enabled debug.

12:33:11,559 DEBUG processing method public java.lang.String com.company.my.support.mongo.functionality.SMModificationDetails.toString()                     [http-nio-8080-exec-2] ModelPropertyParser
12:33:11,559 DEBUG processing method public int com.company.my.support.mongo.functionality.SMModificationDetails.hashCode()                                  [http-nio-8080-exec-2] ModelPropertyParser
12:33:11,560 DEBUG processing method public groovy.lang.MetaClass com.company.my.support.mongo.functionality.SMModificationDetails.getMetaClass()            [http-nio-8080-exec-2] ModelPropertyParser
12:33:11,560 DEBUG validating datatype groovy.lang.MetaClass against 12 keys, got groovy.lang.MetaClass                                                                   [http-nio-8080-exec-2] ModelPropertyParser
12:33:11,560 DEBUG inspecting groovy.lang.MetaClass                                                                                                                       [http-nio-8080-exec-2] ModelPropertyParser
12:33:11,560 DEBUG validating datatype MetaClass against 12 keys, got MetaClass                                                                                           [http-nio-8080-exec-2] ModelPropertyParser
12:33:11,560 DEBUG validating datatype MetaClass against 12 keys, got MetaClass                                                                                           [http-nio-8080-exec-2] ModelPropertyParser
12:33:11,560 DEBUG added param type groovy.lang.MetaClass for field metaClass                                                                                             [http-nio-8080-exec-2] ModelPropertyParser

@iWebi
Copy link
Author

iWebi commented Mar 31, 2014

FYI Its a Jersey JaxRs resource service for which I am integrating swagger. gradle dependencies are

 'com.wordnik:swagger-jersey-jaxrs_2.10:1.3.4', 
'com.fasterxml.jackson.core:jackson-core:2.3.0',
"com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.0.0",

@iWebi
Copy link
Author

iWebi commented Apr 1, 2014

Can anyone provide me a work around? Is this a bug? Am planning to change all my classes from groovy to java to proceed further. This is a painful process. Want to know if this indeed is a problem? or am I missing anything?

@fehguy
Copy link
Contributor

fehguy commented Apr 1, 2014

If you can help create a test case to reproduce the issue, we can help. It
should honor the annotation so yes, this is a bug
On Apr 1, 2014 11:44 AM, "Suman Jakkula" notifications@github.com wrote:

Can anyone provide me a work around? Is this a bug? Am planning to change
all my classes from groovy to java to proceed further. This is a painful
process. Want to know if this indeed is a problem? or am I missing anything?

Reply to this email directly or view it on GitHubhttps://github.com//issues/519#issuecomment-39242825
.

@azhawkes
Copy link
Contributor

azhawkes commented Apr 9, 2014

I have been suffering from this same issue. Please see the below test case which demonstrates @JsonIgnoreProperties being ignored.

https://github.com/azhawkes/swagger-core/commit/e55630dc28a45a6e7f039db01131e4a6cde5787e

If you run "mvn test" in my fork, you'll see the failure.

Please note that @JsonIgnore is handled fine; it is the class-level annotation @JsonIgnoreProperties that is totally ignored by ModelPropertyParser.

Because a huge number of Groovy meta-properties are added at runtime, using the regular @JsonIgnore is not an option. As it currently stands, there are so many Groovy meta-properties being serialized that swagger-ui crashes my browser.

@azhawkes
Copy link
Contributor

azhawkes commented Apr 9, 2014

Pull request submitted that should fix the issue... hope that helps.

@azhawkes
Copy link
Contributor

Just a note for anyone Googling... @fehguy merged my fix into the development branch today and it's been built in 1.3.5-SNAPSHOT. Using 1.3.5-SNAPSHOT, I'm now able to use Groovy models just fine like this:

import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoredProperties(["metaClass"])
class SampleModel {
    String name
    int age
}

@webron
Copy link
Contributor

webron commented Mar 10, 2015

@fehguy - is this still an issue for 1.5? Doesn't the Jackson parsing read these annotations now?

@fehguy
Copy link
Contributor

fehguy commented Mar 11, 2015

Will add tests and close after confirming.

@fehguy fehguy modified the milestones: v1.5-M2, v1.5 Mar 11, 2015
@fehguy fehguy self-assigned this Mar 11, 2015
@fehguy fehguy added the P2 label Mar 11, 2015
@fehguy
Copy link
Contributor

fehguy commented Mar 13, 2015

@fehguy fehguy closed this as completed Mar 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants