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

nullable subjson #133

Closed
Kleinast opened this issue Jul 12, 2018 · 3 comments · Fixed by #173
Closed

nullable subjson #133

Kleinast opened this issue Jul 12, 2018 · 3 comments · Fixed by #173

Comments

@Kleinast
Copy link

Kleinast commented Jul 12, 2018

Hi,

Is there a way to match that json property can be an object matching my matcher AND can also be null:

{
  "id": "@integer@",
  "title": "@string@",
  "image": {
    "title": "@string@",
    "alt": "@string@",
    "url": "@[email protected]()"
  },
  "content": "@string@",
  "description": "@string@",
  "cookTime": "@integer@",
  "preparationTime": "@integer@",
  "coverNumber": "@integer@",
  "ingredients": "@string@",
  "type": "recipe"
}

But my image object can be null like this:

{
  "id": "@integer@",
  "title": "@string@",
  "image": null,
  "content": "@string@",
  "description": "@string@",
  "cookTime": "@integer@",
  "preparationTime": "@integer@",
  "coverNumber": "@integer@",
  "ingredients": "@string@",
  "type": "recipe"
}

Thanks for your help

@norberttech
Copy link
Member

norberttech commented Aug 11, 2019

Hey, sorry at this moment it's impossible. But I think it should be possible to create something like:

{
   "image":"@[email protected](optional(), match(...))"
}

This would require to create json match and match expander.

@norberttech
Copy link
Member

Hey, I'm happy to let you know that after I merged #173 following code will work just like you expected:

(new MatcherFactory())->match(
  '{"image":null}',
  '{"image":"@null@||@[email protected]({\"url\":\"@[email protected]()\"})"}'
);

(new MatcherFactory())->match(
  '{"image":{"url":"http://image.com"}}',
  '{"image":"@null@||@[email protected]({\"url\":\"@[email protected]()\"})"}'
);

(new MatcherFactory())->match(
  '{"image":{"url":"http://image.com"}}',
  '{"image":"@[email protected](optional(), match({\"url\":\"@[email protected]()\"}) )"}'
);

Feel free to use dev-master version in order to test it or wait for 4.0 release (that is coming soon!)

@Kleinast
Copy link
Author

Awsome ! thx @norzechowicz

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

Successfully merging a pull request may close this issue.

2 participants