-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Using toString() on Serialization Fail. #4800
Comments
Jackson is highly configurable. You could register a custom serializer. The advantage of using existing features and existing configurability - you don't have to wait for code changes and a new release. We can't just keep adding extra features just because users don't want to try the existing features. |
Similarly, there is
I think that's huge difference and seems way more complex. So yeah, since we know for which object ( |
Thank you for your suggestion. Indeed, custom serialization can effectively solve this problem. |
OK,I will follow your suggestion and solve this problem through custom serialization. |
In this case, why not use Mix-in Annotations to annotate Having to use custom serializer should really be the last resort, fwtw. |
LOL someone changed HttpMethod from Enum to Class. |
Had the same thought, was going to suggest: public abstract class EnumLikeMixin {
@JsonValue
public abstract String name();
}
...
objectMapper.addMixIn(HttpMethod.class, EnumLikeMixin.class) Also, maybe spring-projects/spring-framework#33870 can & should do that internally, seeing how they've already done similar thing before: https://github.com/spring-projects/spring-framework/blob/37b110a181baa2249c75d028dfea3de58a17a2f0/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java#L767 (assuming your usage is via Spring's |
@yihtserns Good suggestion! |
Wow, your plan looks very elegant and can solve this type of problem.👍 |
Is your feature request related to a problem? Please describe.
I encountered a problem, for example, when serializing: org.springframework.http.HttpMethod, it currently throws an exception because it does not provide a get method for the property, but provides toString().
Describe the solution you'd like
I hope to serialize objects that do not provide property methods, without throwing exceptions, but by calling the toString method to complete the processing. I was wondering if it's possible to add the FAIL_USING_TO_STRING attribute in: com. fasterxml. jakson. databind. serializationFeature to solve this problem?
Usage example
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: