-
-
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
Add support for serializing boolean
/Boolean
as number (0 or 1)
#1480
Comments
Ok. To some degree this could perhaps be covered by supporting variants of So it may make sense to add support for some values, but also define limits: it is not practical to support essentially unbounded set of variations. Having said that, I think that deserialization of 0 and 1 (or, actually, 0 and non-0) is already supported, as well as String versions of "true" and "false". Serialization as a number is probably not yet supported but would be doable via use of |
While I do see (v2.8.5) com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseBoolean(JsonParser p, DeserializationContext ctxt) looks for a int in practice (see test case below), I get the following error:
There seems to be some overlap between |
@jwilmoth At this point However, string values "0" and "1" should by default be coercible. So perhaps there is a codepath that is not doing proper checks? One question on code snippet: what does class |
Oh. I spoke too soon -- no, only JSON numbers 0 and 1 are accepted, not String value. This is by design at this point. I will have to think about how to proceed. I don't think adding aliases for default is the best way, and instead should somehow use |
boolean
/Boolean
as number (0 or 1)
Ok: I think what I'll do is tackle serialization as 0/1 first, using Question of alternate String representations is more difficult, and a new issue should be filed for that. |
FWIW here's the definition of the Foo class:
|
Converting some older data formats means serializing & deserializing Java's boolean fields into 1 and 0 numbers as well as "T" and "F" characters. This post (http://stackoverflow.com/questions/26827343/jackson-serialize-boolean-to-1-0-instead-of-true-false) describes a custom serializer, but I believe there's value in including a couple additional serializers with the library itself.
The text was updated successfully, but these errors were encountered: