Opendaylight convert from builder to JSON - opendaylight

I have defined a YANG model for which I constructed an object using the builder of this model in my java code. Now I want to serialize this as a JSON string. I am not sure how to proceed. Using builder.build() gives me a string but the generated string is not the expected json.
Thanks for any help/pointers. Regards, Ranga

The following, was suggested by Richard Kosegi of the JSON-RPC development team:
https://lists.opendaylight.org/pipermail/jsonrpc-dev/2019-July/000322.html
I made a few modifications and got it working. Just posting here to share knowledge.
Ranga

Related

Return laravel response as csv instead of json

I know that any array response will be converted to json in laravel by default, but i was wondering if there is a way to return the response as csv without installing any third-party library.
I need to make one controller action returns a csv instead of JSON.
Thanx for your advice,
You can't do that without writing a lot of code.
Take a look at this code which is the minimum you will have to do to achieve it.
Or just install the package and enjoy.

Swagger return response: "can't parse JSON. Raw result:"

I am not sure why this is happening. My return statement for spring boot rest controller is something like below
return ResponseEntity.status(HttpStatus.OK).body("Successfully added");
Now on swagger UI i see response as below
can't parse JSON. Raw result:
Successfully added
why is this happening ?
This is happening because you are returning a string literal instead of a JSON object. I presume your return type would have been ResponseEntity<String> but this would not work and you would need to specify an object in the body. You can create a POJO that will hold the message for you, something like this:
public class YourResponseClass {
private String message;
//Constructors, getter and setter
}
Then while returning you need to change the return type to ResponseEntity<YourResponseClass> and then return your response:
return ResponseEntity.ok(new YourResponseClass("Successfully Added."));
Late to the game but will share my solution to this issue, as it surfaced for me in a Python Flask-based REST backend I was developing recently. You could have NaN values in your JSON, if your issue was similar to mine, albeit in Python.
My underlying issue
I too was getting "can't parse JSON" on the swagger side. Turns out that Python's standard library json import will allow "modern" but not-officially-JSON types, such as "NaN". And doing some calculations with floats and voila...As a strict parser fails with a type such as NaN, it's worth checking that you don't have these in your request JSON response.
Solved it with an encoder class
Though not a Java-specific answer, maybe my Python solution can help you solve the issue.
json.dumps(yourdata, cls=NumpyEncoder)
Where NumpyEncoder is some class that converts NaN values to JSON and/or your acceptable specifications. It might be the case that you too can include some encoder class in your code to remove NaN and/or other artifacts.
See my so answer for Python implementation details.
It is hard to say without seeing more code and the actual Swagger JSON, but it seems like the JSON has a syntax issue. Run it through a JSON validator to confirm. There are plenty of websites for this if you Google it.
The response type should be "text/plain" (produces = "MediaType.TEXT_PLAIN")

Issue while Executing XPath Function in Automation anywhere

I'm trying to use Execute XPath Function in automation anywhere.
In the response I'm getting the value as "MS.Internal.XML.XPath.XPathSelectionIterator"
XPath looks like :
//GetEmployees/Employee/text()
I'm sure that xpath is correct since I have tested with Java code.
Looks like the control is returning an object instead of text string.
Is there a way we can do it ?
Got the answer to this one by trial and error.
Was trying to parse soap response and I believe it was facing an issue with namespace.
got wit working by using the following expression
string(//soap:Envelope/soap:Body/*[name()='GetEmployees']/*name()='Employee'])
Hope this helps and some one could improve it further.

Custom query parameter name in RAML

I'm trying to use RAML to describe following API call
PUT /api/v1/kv_store?{key}={value}
It's a simple key-value storage. I need to specify that key value can be any string, and API console should give users possibility to enter it as well as any other parameter.
Is it doable at all? I'm reading RAML 1.0 spec and can't find a way to do it, so small example will be really great.
Your are doing it completely wrong.
please read Documentation.
Correct way to implement QueryParameters by following code.
As this will cater your http://api/v1/kv_store/
/songs:
put:
queryParameters:
id: number
name: string
type: string
album: number

How do I parse a POST to my Rails 3.1 server manually?

Scenario:
I have a Board model in my Rails server side, and an Android device is trying to post some content to a specific board via a POST. Finally, the server needs to send back a response to the Android device.
How do I parse the POST manually (or do I need to)? I am not sure how to handle this kind of external request. I looked into Metal, Middleware, HttpParty; but none of them seems to fit what I am trying to do. The reason I want to parse it manually is because some of the information I want will not be part of the parameters.
Does anyone know a way to approach this problem?
I am also thinking about using SSL later on, how might this affect the problem?
Thank you in advance!! :)
I was trying to make a cross-domain request from ie9 to my rails app, and I needed to parse the body of a POST manually because ie9's XDR object restricts the contentType that we can send to text/plain, rather than application/x-www-urlencoded (see this post). Originally I had just been using the params hash provided by the controller, but once I restricted the contentType and dataType in my ajax request, that hash no longer contained the right information.
Following the URL in the comment above (link), I learned the how to recover that information. The author mentions that in a rails controller we always have access to a request variable that gives us an instance of the ActionDispatch::Request object. I tried to use request.query_string to get at the request body, but that just returned an empty string. A bit of snooping in the API, though, uncovered the raw_post method. That method returned exactly what I needed!
To "parse it manually" you could iterate over the string returned by request.raw_post and do whatever you want, but I don't recommend it. I used Rack::Utils.parse_nested_query, as suggested in Arthur Gunn's answer to this question, to parse the raw_post into a hash. Once it is in hash form, you can shove whatever else you need in there, and then merge it with the params hash. Doing this meant I didn't have to change much else in my controller!
params.merge!(Rack::Utils.parse_nested_query(request.raw_post))
Hope that helps someone!
Not sure exactly what you mean by "manually", posts are normally handled by the "create" or "update" methods in the controller. Check out the controller for your Board model, and you can add code to the appropriate method. You can access the params with the params hash.
You should be more specific about what you are trying to do. :)

Resources