Skip to content
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 specifying an override for converting null for String values to empty String #1072

Closed
cowtowncoder opened this issue Jan 7, 2016 · 3 comments

Comments

@cowtowncoder
Copy link
Member

There are some cases where a specific coercion from null token (JsonToken.VALUE_NULL) into empty String ("") would make sense. One example is when processing XML input, where there is no low-level distinction between empty String and null; and since parser implementation does not have enough context to determine expected type, it simply returns null as token.
At higher level, however, it is important to be able to coerce this into empty String.
For more background, see FasterXML/jackson-dataformat-xml#162.

This could be achieved quite easily via StringDeserializer implementation by return empty String from getNullValue(). However: since such coercion should not be done in cases where null comes from native null type (or is otherwise unambiguous), some mechanism is needed to distinguish between cases where this is and is not desired.

The are many possible ways to pass/access this information, including contextualization of StringDeserializer, or even just dynamically from within getNullValue(), so I will leave the exact mechanism open.

One thing to check is Afterburner, which can override standard String handling: it should not change behavior of "null-to-Empty-String" coercion.

@cowtowncoder cowtowncoder changed the title (2.8) Add support for specifying an override for converting null for String values to empty String Add support for specifying an override for converting null for String values to empty String Sep 30, 2016
@cowtowncoder
Copy link
Member Author

Sort of related to #1402; but not quite the same since this would probably operate at lower level.

@cowtowncoder
Copy link
Member Author

Note: with #1402, it is actually possible to convert nulls into empty String with:

public class Bean {
   @JsonSetter(nulls=JsonSetter.Nulls.AS_EMPTY)
   public String neverNullString = "";
}

so it is not clear whether this feature is needed or not, after all.

@cowtowncoder cowtowncoder removed the 2.9 label Mar 8, 2017
@cowtowncoder
Copy link
Member Author

Actually I think #1402 might do for now; will re-file if I missed something obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant