Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

jaydata maps an empty string to null #276

Open
bizlina opened this issue Nov 11, 2016 · 3 comments
Open

jaydata maps an empty string to null #276

bizlina opened this issue Nov 11, 2016 · 3 comments

Comments

@bizlina
Copy link

bizlina commented Nov 11, 2016

Hi,

I've used JaySvcUtil to generate the entity model out of my oData service. The description is correct generated. I have multiple string keys for one Entity. A oData call for that Entity gives me, for example, the following result (the yellow marked properties are the key columns):

image

One of the key columns (THEME) contains an empty string. After mapping with jaydata the empty string is transformed to "null". This gives me an valildation error because the key filed is required and seems to be null. See the following screenshot.
image

How can I resolve this issue? Is there any possibility to tell jaydata that an empty string is okay for the a field that is defined as "Edm.String"?

@ysmoradi
Copy link

I've no problem with this default behavior, but if you have a problem with that, you can do something like this:

                var originalRequired = $data.Validation.EntityValidation.prototype.supportedValidations["$data.Array"].required;

                $data.Validation.EntityValidation.prototype.supportedValidations["$data.Array"].required = function required(value, definedValue) {
                    return originalRequired.apply(this, arguments) && value.length != 0;
                }

The original required of jaydata for arrays is (array != null) condition, but I think that empty array should results in a required error too, so I've rewritten that with a code I've provided to you (-:

@bizlina
Copy link
Author

bizlina commented Nov 14, 2016

Thanks for your answer. If i replace "$data.Array" with "$data.String" then I can stop for all key fields with type "Edm.String". So far so good. But at this point my key filed has already the value "null".

Is there a possibility to step in earlier, for example, at the point of mapping from odata to jaydata?

@bizlina
Copy link
Author

bizlina commented Nov 15, 2016

In the meantime I found out, that the "problem" is in the saveChanges() method of EntityContext.js. This is an excerpt of the saveChanges-method:
image

In the variable "memDef" in line 1387 the field is still correct filled with an empty string. In the following secquence the control flow get into the if-condition and with String as value for "memDefType" in the switch-case. In line 1404 my property get's assigned to null.
As you can see here:
image

The empty string is technical correct and I need to display this empty string in my application. Is there a similar way to override the default value as @ymoradi provided in his answer for the validation?

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

No branches or pull requests

2 participants