-
Notifications
You must be signed in to change notification settings - Fork 237
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
Custom mappings for @JsonSerialize #498
Comments
I would like to have this feature as well. It would be even better if you could register Jackson serializers directly in the configuration (sadly I guess it's very difficult/impossible to implement) Use case : I have an API project where I register a custom objet mapper used by Jersey when it (de)serializes data between my API and my frontend. I register it using this : @Provider
public class JsonMapperProvider implements ContextResolver<ObjectMapper> {
@Override
public ObjectMapper getContext(final Class<?> type) {
return new ObjectMapper()
// Register other modules
.registerModule(getLocalDateTimeModule());
}
private static SimpleModule getLocalDateTimeModule() {
var module = new SimpleModule(
"LocalDateTime",
Version.unknownVersion()
);
module.addSerializer(new LocalDateTimeJsonSerializer()); // LocalDateTimeJsonSerializer extends StdSerializer
module.addDeserializer(LocalDateTime.class, new LocalDateTimeJsonDeserializer()); // LocalDateTimeJsonDeserializer extends StdDeserializer
return module;
}
} Instead of mapping the type manually in the configuration, I could register the serializers to do the job (advantage : no differences between TS generated types and generated JSON) |
- `serializerTypeMappings` and `deserializerTypeMappings` parameters
@jdussouillez there are two problems: getting list of serializers and getting TypeScript type they produce. I looked into it and I don't think this is reasonable. @andrewbents Here is Maven example for your case: <configuration>
<jsonLibrary>jackson2</jsonLibrary>
<jackson2Configuration>
<serializerTypeMappings>
<mapping>org.example.IdSerializer:{ id: string }</mapping>
</serializerTypeMappings>
</jackson2Configuration>
...
</configuration> |
Yeah I knew it would be very difficult to do. It's not a big deal, I will use the |
@vojtechhabarta Do you have a release date for this ? I would like to use this option in my project. Thanks |
@jdussouillez sorry for late response, good news is that it is released in v2.25.695. |
Any idea how the proposed Thanks! EDIT: found it, I did something like:
|
@pcdv thanks for sharing your solution |
Although applying
|
I checked #47 and #60 but still can't figure out a solution for the following problem.
I have a class where a field is annotated with
@JsonSerialize(using = IdSerializer.class)
:which results in
However, the generated type for that field is still
Project
. Is there an existing way to map types for fields annotated in such way? Note thatProject
is used elsewhere, so I can't usecustomTypeMappings
here to map it entirelyThe text was updated successfully, but these errors were encountered: