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

Configure jslt to include keys for null or {} values instead of omitting the key #51

Closed
Mohammadcore opened this issue Jan 23, 2019 · 8 comments
Labels
enhancement New feature or request

Comments

@Mohammadcore
Copy link

Currently keys with null or {} or [] value are omitted. Is there a way to configure this behavior or where in code can I patch this so I force it to include empty/null keys as well.

@larsga larsga added the enhancement New feature or request label Jan 23, 2019
@larsga
Copy link
Contributor

larsga commented Jan 23, 2019

This is something I was thinking we'd have to make configurable at some point. How do you want to configure it? Would a JSLT expression as filter work?

@Mohammadcore
Copy link
Author

Would it have the flexibility of having control over each key (to include or not if null). Or would it be a filter that applies to all keys i.e. include all null keys or exclude all null keys.

@larsga
Copy link
Contributor

larsga commented Jan 23, 2019

I would say a filter to apply to all keys. If you want to control which key is included or not included you can handle that in the transform itself.

@Mohammadcore
Copy link
Author

Mohammadcore commented Jan 23, 2019

let's say it's a filter to apply to all keys. Yet for a use case might be needed to have control per key rather than globally.

Example:

let doestExists = functions:find($arg1)
let doestExistsEither = functions:find($arg2)
{
  "foo" : $doestExists,
  "bar" : $doestExistsEither
}

There should be a means to achieve following results when needed. The global config doesn't cover case 1.

1

{
  "foo" : null,
}

2

{
  "foo" : null,
  "bar": null
}

3

{}

@larsga
Copy link
Contributor

larsga commented Jan 23, 2019

But you already have full control per key in the template. I don't think giving you that control in the filter actually helps you any. It just moves the challenge somewhere else, and complicates the system.

I think I made my mind up:

  • filter applies to all values (of keys)
  • filter can be specified in JSLT
  • filter can also be specified in Java, if desired

@Mohammadcore
Copy link
Author

Technically you are right.
In practice, template is sometimes not easy to change if it is part of another team work or ...

But what you have mentioned is also a great enhancement comparing to have no configuration option.
Thank you very much.

@larsga
Copy link
Contributor

larsga commented Jan 23, 2019

It's true that you can't necessarily change other people's templates, but you can use them as input to your own template. At which point we're back where we started: making the template do what you want is just as easy as doing it in the filter.

I'll make the change. This may require a deeper change in the JSLT API, due to poor initial design. But I'll solve that.

@larsga
Copy link
Contributor

larsga commented Jan 30, 2019

That commit implements the filters, fixing this issue. @Mohammadcore Would be great if you could test this out.

@larsga larsga closed this as completed Jan 30, 2019
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

No branches or pull requests

2 participants