You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Mikael Andersson Wigander (Jira)" <ji...@apache.org> on 2022/03/30 10:11:00 UTC

[jira] [Commented] (CAMEL-12941) camel-bindy - Null as default value for string

    [ https://issues.apache.org/jira/browse/CAMEL-12941?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17514577#comment-17514577 ] 

Mikael Andersson Wigander commented on CAMEL-12941:
---------------------------------------------------

I also second that and my reason is also when later marshalling from POJO to json the Jackson Library will include this as a key with an empty string as value. In comparison to primitives which gets a null value (by definition) if no value.

If a default value is needed, then use defaultValue = "".

In my case I have to define a default value (not ""), create a custom converter for all String fields, which then removes the default string and sets the field to null.

{code}
    public static Object getDefaultValueForPrimitive(Class<?> clazz) {
        if (clazz == byte.class) {
            return Byte.MIN_VALUE;
        } else if (clazz == short.class) {
            return Short.MIN_VALUE;
        } else if (clazz == int.class) {
            return Integer.MIN_VALUE;
        } else if (clazz == long.class) {
            return Long.MIN_VALUE;
        } else if (clazz == float.class) {
            return Float.MIN_VALUE;
        } else if (clazz == double.class) {
            return Double.MIN_VALUE;
        } else if (clazz == char.class) {
            return Character.MIN_VALUE;
        } else if (clazz == boolean.class) {
            return false;
        } else if (clazz == String.class) {
            return "";
        } else {
            return null;
        }

    }
{code}

Using 3.14.1…

> camel-bindy - Null as default value for string
> ----------------------------------------------
>
>                 Key: CAMEL-12941
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12941
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-bindy
>    Affects Versions: 2.22.1
>            Reporter: michael elbaz
>            Priority: Trivial
>
> From 2.18.0 the default value for empty string is "" and it is not possible to set default string value to null please provide a way to do that, maybe the good solution is to set the default value to null when empty and provide the ability to change this with the annotion parameter 'defaultValue' ([related subject|https://stackoverflow.com/questions/38246684/how-to-set-defaultvalue-parameter-in-datafield-camel-annotation-to-empty-string])



--
This message was sent by Atlassian Jira
(v8.20.1#820001)