-
Notifications
You must be signed in to change notification settings - Fork 407
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
PatternJsonProvider: provide a #tryLong and #tryDouble operation similar to #tryJson #694
Comments
Returning the input value (that is a string) does not make much sense for operations whose purpose is to convert to a type other than string. Instead, we could provide a way to specify the default value to use when the conversion fails. For instance:
Return the input string unchanged - same behaviour as This syntax will be preferred over the @philsttr your opinion? |
👍 Sounds good to me |
I made a mistake when describing the behaviour of the However, I'm questioning the utility of this feature: the type of the field is not constant - sometimes a long (or an json object), sometimes a string. This can make consumption of the JSON output at the receiving side challenging. I'm wondering if a better alternative would be to output the original string value in another field whose name is derived from the original. Suppose the following pattern:
or
or
Fields declared in the pattern keep their desired type. Furthermore, errors are clearly identifiable and the faulty value is available for later post processing. |
Now that I think of it... this kind of mechanism could benefit to all JsonProviders. Instead of silently ignoring errors, JsonProviders could add an entry describing their issue under a special root field ( |
I really like this idea.
Since logback already has a generic mechanism for reporting errors (via StatusManager), I'm hesitant to add another. If you feel strongly that having all errors reported inline would be best, I'd like to see this idea more fully spec'ed out, since the simple example for I think a targetted solution for writing un-parsable values as a separate string field is sufficient. |
It may be handy to provide
#tryLong
and#tryDouble
operations similar to#tryJson
.These two new operations would return the input (string) value when the conversion fails instead of
null
.The text was updated successfully, but these errors were encountered: