How to generate a JSON file from stored procedure(SQL) result - java

I want to get the data from DB using stored procedures in the form of JSon file.
In simple words , my output should be json file which should be result of data in DB(based on stored procedure) .How can i move forward?

You have to create Object Mapper which will convert your data to an object (I think there's an apache library that can do this). Then you can use existing APIs to convert your objects to JSON string example of this is Google's or Jackson. When you have the JSON string you can now write it to a file. Hope this helps.

Related

object saved as binary in couchbase

I am using ‘MappingCouchbaseConverter’ from spring library like below
CouchbaseDocument target = new CouchbaseDocument();
mappingCouchbaseConverter.write(myObject, target);
ctx.insert(couchbaseClientFactory.getCollection(
“mybucketName”).reactive(), null, target.getContent());
I am using transactions.
above code writes a binary data insteed of JSON, can anyone please help, how can I write the Json insteed of binary object

How to convert JSON object received in response to REST Client request to a MT940 Swift text file in Java?

How to convert sample JSON given below to a MT940 txt file:
This JSON would be a bad sample to show but hope you get the gist of it...
Just like we have a library in place to parse MT940 strings/txt we also have a library which can help construct a MT940 txt file in Java.
{
"accNumber":"123356",
"openBalInd":"D",
"openBalaDate":"200605",
"curr":"Dollar",
"transactions":[
{
"amount":""434,
"credit/debit":"1000",
"datetime":"20042020"
},
{
"amount":""434,
"credit/debit":"1000",
"datetime":"20042020"}]
}
MT940 is SWIFT message type.
Your input is JSON and the output is MT940 text file.
It is always good to have some java model classes representing your json.
Deserialise json input using Jackson to model you gonna use internally.
Use your own library or some third party like https://www.prowidesoftware.com/resources/SWIFT-writer to convert your internal model to MT940
Serialize the result into text file.

How to convert GenericRecord to a json string corresponding to the schema given in Avro

I have a requirement where i need to store the data in json format in AWS S3, we are currently hitting an enpoint which gives List[GenericRecord], and that needs to be stored in Json format, can any one share a sample code for achieving this. I am unable to deserialize GenericRecord to Json string, and even ObjectMapper writeValueAsString method is also not working on it

parse a string to extract specified content in java

I need to extract NSID from a list of string which is stored in a file.the string look like this.
the string inside jsonFlickrApi() is in json format.
007rebecca#gmail.com|jsonFlickrApi({"user":{"id":"21849273#N06", "nsid":"21849273#N06", "username":{"_content":"eire5555"}}, "stat":"ok"})
If I want to parse this and get the nsid, in java what approach i should take.
Should I write a parser or is there any library available to parse this json inside jsonFlickrAPI()
The string is a mix of a json and some other text. You may try to split the json part and then can use a json parser to retrieve nsid easily.There are various java json parsers available such as GSON.

How to get JSON content from a RESTful server to a Android client?

I've built a REST server that automatically retrieves data from my database and returns it as JSON. I want to know, how I can get this JSON content to my mobile and turn it into a string so that I can store this in the mobile's database.
First you need to be able to parse your JSON string. For a simple parser I gave an answer earlier here:
getting Json result in Android
Just parse through the list and add them to the database. There are different database tutorials out there.
Database tutorial: http://www.vogella.de/articles/AndroidSQLite/article.html
To make it as easy as possible try to find out small tutorials for different sub tasks like REST to JSON and database handler.
Here is a tutorial for JSON parsing from a REST webservice:
http://www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/
Here is another more simple JSON example:
http://inchoo.net/mobile-development/android-development/simple-android-json-parsing-example-with-output-into-listactivity/

Categories

Resources