Convert Object to NGSI10v1 payload and NGSI10 v1 response to OBJECT? - json

I am looking for solution in Java to convert Object to NGSI10v1 payload (Json) and NGSI10v1 respose(Json) to Object .
Can i do that?
How can i do?

please have a look at this node module
https://www.npmjs.com/package/fiware-orion-client
particularly if you have a look at https://github.com/telefonicaid/fiware-SDK/blob/master/Javascript/orion/ngsi-helper.js
source file you will find two useful methods provided by the NgsiHelper object, one for parsing NGSI payloads to JS objects and the other to convert JS objects to NGSI payloads.
best

Related

Rest assured api automation- posting big json payload with few parameters or dynamic data

Rest assured api automation-how to post big json payload in body with few parameters or dynamic data .
xxxx is the data need to be passed dynamically with every post request.
It can be from csv file or some random data.
{
Id:xxxx
Name:test123
City:Edison
Profile :{
Startdate: xxxx
Enddate:xxxx
Product: abcd
}
Renewal: {
Auto renewal: yes
Term: 1 year
}
}
Rest-Assured supports many ways to deal with json payload
String: not good for this situation
Map: for simple and not too much key-value pair
POJPO: the main option here
For your case, I would recommend the POJO approach.
you create a Java object to map with Json object,
then use one of the Serialize/Deserialize libraries (jackson, gson) to convert Java object to Json object.
Rest-assured will automatically do converting for you, you just declare the lib in classpath
More infomation here: https://github.com/rest-assured/rest-assured/wiki/Usage#serialization
For the part: It can be from csv file or some random data. --> it can be easily achieved by supporting from Test framework (Junit5 or TestNG)

does smooks support json output

Does smooks support json output or thirdparty plugin for json?
For example, to do XML-to-JSON or EDI-to-JSON
I see it has json reader/parser, but can't seem to find an output/writer.
TIA!
Not directly, but it would support populating of a Java Object model from e.g. XML or EDI and then you could use something like Jackson to serialize the Java to JSON. So should be easy enough to do once you get the data into a Java Object model.
Also note that you do not need to create an actual Java Object model. You can create what Smooks calls a "virtual object model", which is basically collection types (Maps, Lists etc).

Pass JSON object vs JSON string in HTTP POST

I'm building a REST API in JAVA and C# and I was wondering about the way I should pass data to those services.
What I'm familiar with as the right way is to send JSON object as the data in the POST body:
{name:'Dor'}
but I can also pass a string and parse the JSON in my service:
'{name:'Dor'}'
What is the preferable way from performance factor? or any other factors?
Basically, if you need to send the json data across via jquery, then we need to use stringify, else the data would be serialized into to key=value pair.
So, you cannot send the json object directly via jquery ajax method.
How it works behind the hood:
In $.ajax function, if we provide data as
data :{key1:"value1", key2:"value2"}
is serialized to key1=value1&key2=value2
if we provide data as
data :'{key1:"value1", key2:"value2"}' or JSON.stringify({key1:"value1", key2:"value2"})
is sent as {key1:"value1", key2:"value2"}
So, what we can conclude is that, we cannot pass json object directly via jquery, we can send only json string. Hope this clarifies everyone.

Need a JSON parser for Unity3d

I need to deserialize some JSON objects. I tried to use Tiny-json library, but it's too slow. I tried to use Newtonsoft.Json, but it fails in webplayer with this error:
MissingMethodException: Method not found: 'System.Collections.ObjectModel.KeyedCollection.
What JSON parser do you recommend?
You can try one of these open source solutions:
https://github.com/jacobdufault/fullserializer
https://github.com/mtschoen/JSONObject (https://www.assetstore.unity3d.com/en/#!/content/710) I am using this one most of the times, it's versbose but does its job well, not sure about performance however
Or go with paid ones:
https://www.assetstore.unity3d.com/en/#!/content/11347
Unity 5.3 added Native support of Json Serializer. It is faster than others.
JsonUtility.ToJson to convert a class to Json.
JsonUtility.FromJson to convert Json back to class.
For complete example and information regarding json arrays, see
Serialize and Deserialize Json and Json Array in Unity

How to return JSON from a servlet based on request parameters

How do I use JSON in java servlet? Using the URL, to pass parameters from a POST servlet, the JSON would respond based on the URL parameters.
You need a JSON library in Java. With that library, you will be able to serialize Java Objects into JSON objects, and send them through HttpServletResponse instance in your Servlet.
"How do you use it"?
JSON is simply one way of representing hierarchical data (such an an object model) in a flat text format (such as an HTTP body, or filesystem file). So you'd use it to represent hierarchical data in these situations.
If you mean how do you parse/create it, there are many mature libraries for JSON handling.
Perhaps a specific situation or use case would assist in pinning down your question, if the above is not the answer you were looking for.