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

Passing value from DB to JSLT node #322

Open
iammurugesh opened this issue Feb 6, 2024 · 8 comments
Open

Passing value from DB to JSLT node #322

iammurugesh opened this issue Feb 6, 2024 · 8 comments
Labels
support Users asking how to solve a specific issue

Comments

@iammurugesh
Copy link

Hi Team,

We have a requirement where we convert a JSON from one structure to other. However in target structure we do have values from source json and some value directly from database? Is there a way we can write expression or code to fetch data from Database and append to a node?

Or anyways to achieve this?

@larsga larsga added the support Users asking how to solve a specific issue label Feb 6, 2024
@larsga
Copy link
Collaborator

larsga commented Feb 6, 2024

I guess the use case here is that instead of the usual model of transform(json) => result you have a case where the model is transform(json, db state) => result`?

If so, one way to do it is indeed to add the necessary db state to the input. That is ugly, though. The best way to solve this is to use the JSLT API and pass parameters to the transform. You can build an entire object and pass that, or set a bunch of single values. Parameters are available as variables inside the transform.

@iammurugesh
Copy link
Author

Thanks for the quick response @larsga . Will check this.

@iammurugesh
Copy link
Author

Can we insert a javascript code in a JSLT field? That may be a work around here

@iammurugesh
Copy link
Author

iammurugesh commented Feb 6, 2024

I will also explain my scenario here. Any help would be much appreciated!!!

we are currently building a pass through system, where we get request from System A in a JSON format, we need to convert that to a different JSON format and pass to system B and vice versa. Here we will have most of the data available from system A, but some data we need to take from our system (the pass through system).

@larsga
Copy link
Collaborator

larsga commented Feb 6, 2024

Can we insert a javascript code in a JSLT field?

In that case we'd need to extend JSLT with a JavaScript interpreter running inside the JVM that could somehow connect to your database. This is far too complex, and I also don't think you need it.

Here we will have most of the data available from system A, but some data we need to take from our system

Why can't you write Java code to make the data from your system available as parameters?

@iammurugesh
Copy link
Author

Why can't you write Java code to make the data from your system available as parameters?
This we can do , but how can this be passed to JSLT, any examples?

@larsga
Copy link
Collaborator

larsga commented Feb 6, 2024

Did you follow the link to the documentation in the first comment I made?

@iammurugesh
Copy link
Author

Hi , Yes i did. Still figuring out how to fit that in our approach. Will keep this group posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Users asking how to solve a specific issue
Projects
None yet
Development

No branches or pull requests

2 participants