Skip to content

Conversation

@lukas-klausner
Copy link
Contributor

In the deserializer, the value "null" is not accepted for structure and table types and an exception is raised.

In the changed code of my pull request, the value "null" is handled like an initial structure ("{}") or table ("[]").

In my company we need this behavior, because some Java applications serialize empty tables/arrays to the value "null" (e.g. in Swagger "nullable: true").

In the deserializer, the value "null" was not accepted for structure and table types and an exception was raised.
Now the value "null" is handled like an initial structure ("{}") or table ("[]").
@cla-assistant
Copy link

cla-assistant bot commented Dec 28, 2023

CLA assistant check
All committers have signed the CLA.

@alexey-arseniev
Copy link
Contributor

Hi Lukas,

First, thanks a lot for your work and investment in the class!

In general, I am happy with any suggestion, but it shall be compatible, and consistent and do not harm the performance of other scenarios. This I need to validate.

Questions:

  1. Is it a regression? Has it worked differently in previous versions?
  2. Can you please also provide a unit test/example that I can validate (JSON + ABAP)? What is your receiving data type?
  3. Do you have links for Swagger "nullable: true" - if I will integrate the change I will need to document it.

BR, Alexey.

@lukas-klausner
Copy link
Contributor Author

Hi Alexey,

Thank you for your answer.
Sorry I forgot the important detail, that the problem appears only in strict mode. In default mode (non-strict), it is not an issue.

  1. There is no regression. As I know, "null" values have not been accepted for structures or tables also in previous versions.
  2. I added another commit to my fork with a unit test method that uses "null" as structure value and one as table value. The third unit test method is for a string field and "null". This 3rd test is just an addition and was working even before my changes to the deserializer.
  3. The deserializer of /UI2/CL_JSON already allows "null" for boolean/integer/string values, but not for objects (structure) and arrays (tables). I cannot find a reason for this restriction.
    Docu for nullable OAI 3.0.3: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schemaNullable (There are some discussions around nullable like https://github.com/OAI/OpenAPI-Specification/blob/main/proposals/2019-10-31-Clarify-Nullable.md)
    In current OAI (3.1.0), "nullable" was replaced by "null" specified in JSON Schema (https://json-schema.org/draft/2020-12/json-schema-core)
    In this post https://stackoverflow.com/questions/40920441/how-to-specify-a-property-can-be-null-or-a-reference-with-swagger a structure is declared as nullable.

BR
Lukas

@alexey-arseniev
Copy link
Contributor

Hi Lukas,

Thanks, I understand. The good point, is that null values are accepted and ignored for elementary types, so it will be consistent if the same logic applies to tables and structure.
And thanks for the unit test.
I will merge the request but will adjust a bit coding (maybe) - I will try to reuse logic for elementary types. But we will see.

BR, Alexey.

@alexey-arseniev alexey-arseniev merged commit 71a4f0c into SAP:main Jan 10, 2024
@alexey-arseniev alexey-arseniev added the enhancement New feature or request label Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants