-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
8.4 AlternateTypeProvider #315
Comments
@trycatchblock Its possible this may be a bug. Do you know if there are some LocalDate properties on any of your beans that are nested deeper within the model? |
Not deep. Probably one level deeper. Request has an object which contains LocalDate |
@trycatchblock do you have an example model that I could use to demostrate the problem? |
Sure, this should help you out. The request has an object "Business" which contains a localdate so it's not too deep within th emodel.
|
Also tried overriding with fasterxml's local date serializer and deserializers in config. No luck. public ObjectMapper objectMapper() { |
I'm also having issues with this, one question to understand the issue: Does Swagger support custom de/serializers of jackson? If so, how? |
@jtheuer It absolutely does. Whatever customizations you do with the models via jackson attributes should absolutely be respected. Once you have access to the ObjectMapper that is being used by your application (there should only be one for your application, the swagger stuff should be using the same ObjectMapper that is being used by the application itself), you can customize it just like you normally would. |
I might use the "wrong" way of custom serialization because It don't think that you can infer the document structure from this, should I use something else? I doubt that you can infer from this that the result is an
|
@jtheuer Not sure I follow. If I understand correctly, you want to serialize Geometry as a lat long? If thats the case what you'd do is set up a serializer, just like you have it, and in addition also setup an alternate rule to tell swagger to render the model schema of class JtsWgs84 {
private double lat;
private double lon;
//getters and setters
} @trycatchblock From your previous example, your ObjectMapper method may not have worked as it may have been a different instance of the object mapper than the one that swagger is using. |
Guessing the first part was directed to @jtheuer. That method is using the bean definition in my SwaggerConfig. It says in the readme that I can customize my ObjectMapper and have swagger pick up the bean from there. Is this wrong? |
@trycatchblock Its correct... just a word of caution that if you have multiple object mappers there is a possibility that it may not have worked. We had a few bug fixes related to that so I was just making sure. |
I was unable to find in the code where it was using objectMapper's readValue and writeValue. I also noticed from swagger-core that custom deserializer/serializers are not supported via this issue: Just to make sure I'm not going down the wrong path, can you confirm that custom serialization/deserialization via objectMapper is actually NOT SUPPORTED? If it is, can you point me to the piece of code where objectmapper is being used to read/write? Thanks! |
@trycatchblock I'm not very sure if this is the answer to your question, but here goes. There are two aspects to this.
So given that, lets take a can example of LocalDate. Lets say we decide that we want to represent that date as a ISO8601 format (yyyy-MM-dd) string. In order to do that you need to do two things
Now while the swagger-core may not support this, this library totally supports keeping parity between the swagger representation and what the application uses. Hope that answers your question. If you have a specific example let me know. |
hey, thanks for the detailed writeup above, but the objectmapper and the alternatetypeprovider is still not working for me. I'm happy to debug it myself, but what I wanted to know was where exactly in the library is it using the serializer/deserializer registered in the module for objectwrapper? The only class I see using objectwrapper is the DefaultModelPropertiesProvider which only uses getSerializationConfig and getDeserializationConfig in order to retrieve the properties/fields (to be used to create the [incorrect] models later). I cannot find the actual serializing/deserializing methods (writeValue/readValue) being used anywhere. |
@trycatchblock you'd never see the read and write, because thats not the responsibility of the library. If you wanted to register a custom serializer or deserializer you just have to configure the ObjectMapper that the library uses, just like you would when swagger was not in play. Secondly; possibly why you're geting incorrect models; if you have a custom serializer/deserializer there is no way for swagger to know the shape of the model. So you'd have to provide an alternate type in swagger, or provide the object mapper with a Mixin to provide the shape information. If you can create a fork with a failing test, of your expection, I could take a look at what the bug might be |
Thanks for the above. I just debugged the library and it's not parsing beyond the top level of the request for alternate types so LocalDate is not converted over to string. I'll take a look at the mixin. |
@trycatchblock yes theres a bug fix for that that should be coming up this weekend :) |
Hi,
I've added the example code from the readme to swaggerGlobalSettings() in my swagger configuration class. However, I am still seeing LocalDate in my models. Any ideas?
Thanks!
The text was updated successfully, but these errors were encountered: