-
Notifications
You must be signed in to change notification settings - Fork 19
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
fix: remove jsonb_array and fix jsonb data types such that it can be used in schema design and graphql api #4409
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks fine, but is missing a migration step. I would expect a JSONB_ARRAY to be converted to a JSON Object containing an array of JSON objects.
Not needed, was not useable. |
json has never worked so can't be anything to migrate
If #4323 ends up getting merged before this PR, be sure to remove the following lines after merging with master: molgenis-emx2/backend/molgenis-emx2-rdf/src/main/java/org/molgenis/emx2/rdf/ColumnTypeRdfMapper.java Line 67 in 23d8cb9
Lines 151 to 152 in 23d8cb9
Lines 372 to 373 in 23d8cb9
#4323 contains a test that validates whether each EDIT: Might be some more conflicts as I see |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found some things that might need to be adjusted/improved before we merge it:
- docs ->
use_schema.md
- remove
jsonb_array
- rename
jsonb
tojson
- remove
- Consider front-end json validation, such as:
- try-except with
JSON.parse(json);
- a regex like https://stackoverflow.com/a/32155765 (link needs conversion from PHP though)
- try-except with
- While during row-creation invalid data is not accepted, if editing an existing row this can still be done. See f.e. https://preview-emx2-pr-4409.dev.molgenis.org/json_input_test/tables/#/Test :
input | expected | actual |
---|---|---|
{"key":"value"};alert("test") |
error (not valid json) | "{\"key\":\"value\"};alert(\"test\")" |
"{"key":"value"};alert("test")" |
error (not valid json) | "\"{\"key\":\"value\"};alert(\"test\")\"" |
{}alert("test") |
error (not valid json) | "{}alert(\"test\")" |
"alert("test") |
error (not valid json) | "\"alert(\"test\")" |
- Consider adding tests that include primitives as well (
""
,"string"
,-1
,true
,null
), see also https://datatracker.ietf.org/doc/html/rfc7159#section-3null
is converted to an empty field (should staynull
)
{"key":"value1", "key":"value2"}
yields{"key":"value2"}
. While technically correct, an error or warning would be preferred.
Grotendeels goede punten; uitdaging is dat "string" ook valide json is. Maar we zouden kunnen zeggen dat als het resultaat van de parse geen Map of List is dat we dan het niet valide vinden? |
@mswertz: Normaliter zou ik voorstander zijn van de RFC standaarden zo goed mogelijk te volgen, al is er hier wel een punt te maken dat qua usecase we zelf al datatypes hebben voor string/int/boolean (behalve
* json : validates json format (must be an array or object!)
JsonNode tree = objectMapper.readTree(jsonString);
if(!tree.isArray() && !tree.isObject()) {
throw new MolgenisException("JSON is not an array/object.");
} |
yes, kun jij dat doen of wil je dat ik het doe? |
Conflicts: backend/molgenis-emx2-rdf/src/main/java/org/molgenis/emx2/rdf/RDFService.java
Changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, one question left. I cannot approve so if you agree with comment can you then approve yourself?
} | ||
|
||
export function isJsonObjectOrArray(parsedJson: any) { | ||
if (typeof parsedJson === "object") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't check if it is an array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should allow arrays, see for example: https://jsbin.com/paperodivi/1/edit?html,output
While null
is also an object
, it does fail in the form (probably due to if(!parsed)
):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a quick look if I can fix null
giving the correct error message though (no array/object instead of invalid JSON).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test code for front-end now also added:
molgenis-emx2/apps/molgenis-components/src/components/forms/formUtils/formUtils.test.ts
Lines 380 to 391 in ff6cdbf
describe("isJsonObjectOrArray", () => { | |
test("only JSON object/array should return true (after parsing from JSON string)", () => { | |
expect(isJsonObjectOrArray(JSON.parse('{"key":"value"}'))).toBe(true); | |
expect(isJsonObjectOrArray(JSON.parse('["string1", "string2"]'))).toBe(true); | |
expect(isJsonObjectOrArray(JSON.parse('{"key1":{"key2":["value1", "value2"]}}'))).toBe(true); | |
expect(isJsonObjectOrArray(JSON.parse('"string"'))).toBe(false); | |
expect(isJsonObjectOrArray(JSON.parse('1'))).toBe(false); | |
expect(isJsonObjectOrArray(JSON.parse('true'))).toBe(false); | |
expect(isJsonObjectOrArray(JSON.parse('false'))).toBe(false); | |
expect(isJsonObjectOrArray(JSON.parse('null'))).toBe(false); | |
}); | |
}); |
backend/molgenis-emx2/src/main/java/org/molgenis/emx2/utils/MolgenisObjectMapper.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, just some small thingies.
Quality Gate passedIssues Measures |
@mswertz: I approved and @chinook25 did another review and that feedback is included as well. |
closes #4405
todo:
out of scope: