@JsonIgnore to ignore values on de-serializing from JSON to Java object doesn't work with Swagger

3,237 views
Skip to first unread message

Leny Tan

unread,
Jan 21, 2015, 2:24:08 PM1/21/15
to swagger-sw...@googlegroups.com
Hi, 

We have scenario where we need to ignore values on de-serializing from JSON to Java object ( or basically, it's a read only value field).

As recommended when using Jackson 1.9 and higher, we add:
1. @JsonIgnore on the member variable and the setter method
2. @JsonProperty on the getter method.

It works, however the field is not showing up in swagger. Even though it's a read only field, we still want the field to show in the model schema in the swagger documentation.


We are using swagger-jersey2-jaxrs_2.10 version 1.3.7. I tried to upgrade to version 1.3.12, but still the same issue.

Can you help? Is it a bug or known issue?


Thanks,
Leny

Ron Ratovsky

unread,
Jan 21, 2015, 2:40:11 PM1/21/15
to swagger-sw...@googlegroups.com
It's not really an issue as it works as expected. @JsonIgnore means it will be ignored for both serialization and deserialization so it means that it shouldn't be documented at all.

In your case, you need separate models for the input and output. Note, this doesn't mean your code needs to use the different models, but you'll have to feed it to the documentation.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Leny Tan

unread,
Jan 21, 2015, 4:22:27 PM1/21/15
to swagger-sw...@googlegroups.com
But, we only put the @JsonIgnore on the setter and the member variable, which means ONLY ignore on deserialization. So, it should not be ignore on serialization.




thanks
Leny

Ron Ratovsky

unread,
Jan 21, 2015, 4:40:55 PM1/21/15
to swagger-sw...@googlegroups.com
That's Jackson's way of reading it, it's not how Swagger parses it. Eventually, in the documentation itself there would have to be two separate models. Since right now it does not parse it as you expect it to, you'll have to use two separate models (again, for documentation, not for use with your application).

However, I'd suggest you open an issue on swagger-core requesting support for such a feature. It may not be implemented soon, but it's certainly a nice idea to consider.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ashwin

unread,
Feb 10, 2015, 7:11:43 PM2/10/15
to swagger-sw...@googlegroups.com
I am using org.codehaus.jackson.annotate.JsonIgnore annotation on a model (response class) attribute but the attribute shows up in the actual API response (not documentation). This was not the case before swagger was integrated. Does swagger effect the jackson deserializion on the actual response returned by the service.

Ashwin

unread,
Feb 10, 2015, 7:12:23 PM2/10/15
to swagger-sw...@googlegroups.com
I am using swagger-jaxrs_2.10-1.3.12.jar.

tony tam

unread,
Feb 10, 2015, 8:11:05 PM2/10/15
to swagger-sw...@googlegroups.com
Your version of jackson is too old--you'll need 2.x (suggest 2.4.x)

On Tuesday, February 10, 2015 at 4:12:23 PM UTC-8, Ashwin wrote:
I am using swagger-jaxrs_2.10-1.3.12.jar.

Ashwin

unread,
Feb 10, 2015, 9:48:19 PM2/10/15
to swagger-sw...@googlegroups.com
How did you know the version of jackson I am using? 

tony tam

unread,
Feb 10, 2015, 11:21:20 PM2/10/15
to swagger-sw...@googlegroups.com
Pattern recognition :)  Actually the package of org.codehaus means jackson 1.x, while com.fasterxml implies 2.x +

Ashwin

unread,
Feb 17, 2015, 2:17:46 PM2/17/15
to swagger-sw...@googlegroups.com
Is there any way to get swagger working with 1.X of Jackson. I am restricted to use this version that comes with the jboss version that we use. Let me know if there are any other options. Thanks!

Ron Ratovsky

unread,
Feb 17, 2015, 2:20:37 PM2/17/15
to swagger-sw...@googlegroups.com
There should be no problem using Jackson 2.x alongside Jackson 1.x. They use completely different package names and should impose no conflicts.

On Tue, Feb 17, 2015 at 9:17 PM, Ashwin <ashwin.da...@gmail.com> wrote:
Is there any way to get swagger working with 1.X of Jackson. I am restricted to use this version that comes with the jboss version that we use. Let me know if there are any other options. Thanks!

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages