Noflo .fbp array initiallizer - noflo

I'm using noflo and am trying to send an array as an initiallizer. There doesn't seem to be a supported (or at least documented) way to do this.
I'm currently using:
'["Kicker"]' -> IN Nodes(strings/ParseJson)
'{"in":"go!"}' -> IN Config(strings/ParseJson)
Nodes() OUT -> NODES MyComponent(noflotest/Universe)
Config OUT -> CONFIG MyComponent()
Is there a better way to do this?

Currently arrays and other complicated data structures are not supported in the .fbp syntax. There is a feature request about this.
Right now you have three options:
If FBP parser accepts your string (see the matching rules), you can first send it to the strings/ParseJson component to turn it to the appropriate data structure
Reading the value from a JSON or YAML file and passing it through the appropriate parser component
Converting your graph to the JSON graph format

Related

Karate DSL: How to pass Scenario Outline variables into a json string

I'm testing a graphQL endpoint. I want to keep the query separate from the feature file so that it can be reused elsewhere. The query has an embedded string which I want to pass in variables from my examples, however, I can't seem to update the query.
Here is the feature file:
Here is the query file:
Any help would be appreciated, thanks.
I think best practice is to read the query part alone as a text file, and then form the JSON within the test. Your JSON is actually not well-formed because JSON does not allow line-feeds within values, that's why you have the red squiggly line in your screen shot.
Refer articles like this: https://www.katk.dev/graphql-karate
Best practice is to use the variables in the JSON in addition to the query. If not, be aware that you can do placeholder substitution in plain-text using Karate: https://github.com/karatelabs/karate#replace
Also read this part of the documentation: https://github.com/karatelabs/karate#dont-parse-treat-as-raw-text

UnrecognizedPropertyException while parsing YAML file with Jackson

I am trying to parse the following YAML content using Jackson in Kotlin.
template:
# More properties...
noise.max: 0.01
I get this exception:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "noise.max" ...
When I change my YAML to this, it works:
template:
# More properties...
noise:
max: 0.01
It seems like Jackson can't parse nested values if they are noted inline with dots as separators. Is this incorrect YAML, or unconventional?
I know that spring boot can parse this kind of nested YAML params, and I guess they use Jackson for it too. But I can't find a way how I can configure the ObjectMapper so it works.
Can someone please help me an tell me how to configure ObjectMapper or whatever else needs to be done?
In YAML, a dot is not a special character and simply part of the content. The first file contains two mappings, with the inner one having noise.max as key, while the second file contains three mappings, where the innermost has max as key and the one above that has noise as key. These are different structures.
Spring boot maps YAML to Properties. It does so by concatenating nested keys via dots. If you do this, the result of both your YAML files will be:
template.noise.max = 0.01
And that is why it works with Spring boot.
Property files are a list of key/value pairs while YAML files describe a possibly complex node graph. Spring boot uses YAML as syntax sugar for Properties. If you use Jackson, you process the actual structure and not the simplified one that you get with Spring boot.
So the bottom line is: If you want to use a YAML library for loading YAML, you will not have this „feature“ of replacing nested maps with dots in keys. Theoretically you could use SnakeYAML to do some preprocessing at the event level to split such keys so that what you want is possible, but I wouldn't recommend it.

Use encoded object query param for GET request

While designing the API with with the team a suggestion was forwarded in regards to some complex query parameters that we sent which need to be encoded as objects, arrays of objects, etc. Suppose I have a route GET /resource/ and I want to apply a set of filters directly in the query params. The object literal structure of this filter would be something like
filter: {
field1: {
contains: 'value',
notin: ['value2', 'value3']
},
field2: {
greaterThan: 10
}
}
Encoding this in the url, via a query string parser such as the qs node module that express.js uses internally, would be cheap on the backend. However 1) The generated url is very hard to read, if a client wants to connect with the API he would need to use an encoding library and 2) I don't think I ever encountered the use of query params like this, it looks a little bit of overengineered and I'm not sure how used it is and if it is really safe.
The example above would yield query params such as:
GET /resource/?field1%5Bcontains%5D=value&field1%5Bnotin%5D%5B0%5D=value2&field1%5Bnotin%5D%5B1%5D=value3&field2%5BgreaterThan%5D=10
Does this practice of sending url query parameters that happen to be complex objects have some standards or best practices?
We implemented a different solution for filtering, when the list of possible parameters was very long. We ended up doing it in two steps, posting the filter and returning a filter ID. The filter ID could then be used in the GET query.
We had trouble finding any best practices for this.

What's the best way to wrangle path patterns in Restkit

I'd like to be able to specify a string, let's say
NSString * pathPattern = /api/elements/:id/subelement/:type
and call a simple function
[pathPattern build:#{#":id" => id, #"subelement" => subelement}]
to generate the URL path.
Obviously I can build a simple category to do this, but does something exist that handles such things in a generic way, and maybe has additional useful features for this kind of thing that I haven't thought of at this time?
Yes, RestKit already injects parameters into path patterns. Internally it uses SOCKit to perform this parameterisation.
It actually uses exactly the format you have in the question and where the parameter names match keys on the supplied object for mapping.
The path pattern can also be used during response mapping to take values back out of the request URL.

Writing simple dictionary using java & google dictionary api

http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=test&sl=en&tl=en&restrict=pr%2Cde&client=te
(replace test with your favorite keyword)
using this i want to write simple dictionary....
problem - api give json output how i get it using java?
Simple Parsing
Per default, JSON will just produce a nested graph of maps and lists. Here is an example of default parsing:
import org.svenson.JSONParser;
// assume json to be a JSON datasets as String
Object o = JSONParser.defaultJSONParser().parse(json);
o will now contain either a map or a list instance, depending on whether the first symbol in the JSON is '{' or '['.