-
Notifications
You must be signed in to change notification settings - Fork 200
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
Enable usage of custom serializers/deserializers #1034
Comments
Acknowledged.
This option is not viable because Enunciate works with the pre-compiled source code and not with the post-compiled bytecode. There's no generic way to "create some custom value" of an object and "get a formatted value from
This functionality could be added if needed.
This is already implemented, e.g.: <enunciate>
<modules>
<jackson dateFormat="date_time"/> Also see the changes requested at #1026 that have already been included in version 2.13.1. For now, I'll keep this issue open to accommodate the suggested configuration enhancement for custom (de)serializers. |
@stoicflame , thank you for your feedback. There is one important issue with default types. There is no a common default value. It depends on company, country, personal opinion. Some people prefer to get timestamp, some in the local date-time format, some with a zone number. My proposal with serializers/deserializers is not a good one. I agree. What can be done - to provide their analog via jackson configuration. Please consider the following example:
It can be shared and used both for request/responses (serialization/deserialization). It is very clear. It is actually an alternative way to specify formats for certain types globally. |
Actually you can close the issue. You have already provided a solution via "examples" in the configuration file. It plays the same role I've described above. And it is really awesome. I could get rid of all annotations, extra dependency, left only plugin and global configuration. |
Can you please again consider adding this functionality. I've seen the issue, which is closed now.
The problem with the solution you offer, via
@TypeHint
and@DocumentationExample
or with Jackson annotation like@JsonSerialize
is that it forces to specify them per each attribute/property/dto object.The beauty of custom serializers/deserializers - is an ability to register global ones per type. For instance per
java.util.Date
, or perZonedDateTime
. Like:After that a developer should not think about this aspect. It dramatically simplifies development.
You might find in the source code all such
JsonSerializer
andJsonDeserializer
, create some custom value ofZonedDateTime
for instance and then get a formatted value fromJsonGenerator
.Or you might add a configuration ability, to add a mapping between certain java type and a custom serializer/deserializer.
Or, in the worst case, but the simplest solution, you might provide a configuration to specify datetime format. And list of java types that should be affected. In the generated examples, you might use it to show the expected string value.
Probably it is enough to handle only serializers, cause it gives a string representation which is the same in the request and response, mostly.
I am talking now only about docs generation. For clients generation it also a challenge to implement it. These serializers/deserializers must be registered.
The text was updated successfully, but these errors were encountered: