How to fetch large JSON response in android Sybase Unwired Platform - java

I know normal parsing in Android and Java .
But , here the case is bit different .
In cases when the default String (300) is set I can fetch JSON String with PAGESIZE being set as somewhat 2096 and I can generate code in Sybase.
But if I want to get data as large which is more than size 300 characters or if 300000 characters then the MBO hit can get it but not via code in Android .
In android code I get TRUNCATED data + some data of JSON fetched after I hit for synchronize
So I need to know how can I fetch large JSON string as result via Android code
.
Kindly note : This question is for Sybase Android application development
A similar question has been posted in SAP forum but yet to answer
http://scn.sap.com/thread/3738150

for large data try to save your data in a database from the
beginning (it's a better practice), then deal with it using SQLite.

Lets asume when you talk about fetching you mean fetching data from a server. 2 years ago the most robust approach was to use the gson library for android to parse the json string element by element.

Related

Read REST api response hosting very large data

I am calling an REST API endpoint which is hosting a very large amount of data. The data quantity is too much that my chrome tab crashes as well (It displays the data for a short time and it's loading even more data causing the tab to crash). Even postman fails to get the data and instead would only return 200 OK code without displaying any response body.
I'm trying to write a java program to consume the response from the API. Is there a way to consume the response without using a lot of memory?
Please let me know if the question is not clear. Thank you !!
A possibility is to use a JSON streaming parser like Jackson Streaming API (https://github.com/FasterXML/jackson-docs/wiki/JacksonStreamingApi) for example code see https://javarevisited.blogspot.com/2015/03/parsing-large-json-files-using-jackson.html
For JS there is https://github.com/DonutEspresso/big-json
If data is really so large then better to split task:
Download full data via ordinary http client to disk
Make bulk processing , using some streaming approach, similar to SAX parsing for XML:
JAVA - Best approach to parse huge (extra large) JSON file
With such split, you will not deal with possible network errors during processing and will keep data consistency.

Storing large jsons on blob field on a oracle database

As the title says, I need to store some big json files on a "blob" field on a oracle database. We've been using the "utl_raw.cast_to_raw" function, which seems to be the suggested way to do it, but we quickly hit the 2000 byte size cap.
I've been looking around for a solution, and the only one I've found points towards converting the Json to a byte array through a webservice (We are using Java instead of C#, but it shouldn't be an issue).
There's something else we can do to get our big jsons on the database without having to relay on a new development?
You should use a CLOB type column, it can store GB of text. It´s not as easy to do CRUD operations with it, but nothing you can´t handle

Java , how can i get JSON from restful(?) web service

Firstly , this is a java program but not Android.
I write a very simple API to get the DB data in Php like below code:
<?php
$query = "Select * from staff order by staff_name";
$reuslt = $mysqli->query($query);
echo json_encode($reuslt->fetch_object());
Suppose that i can get the JSON object in the following URL easily in Android or Php:
http://localhost/Testing/simpleWebService.php
But how can i get it in Java??
I have searched it in Google but the result seems not what i actually want and useful to me
(Reason is i am quite Junior to Java ,Lack of knowledge in Web Service, not accurate keywords inputted........).
I found sth like Jersey, JAX-RS but i don't think this help and the way to get the JSON from the Web Service is complex like that.
Can anyone help ? Thank you very much!!!!!!
The crux of the matter is that you have to replace the behaviour implemented by PHP's json_encode function in Java ie. you have got to find a way to convert the recordset representation of your data to JSON.
1 approach would be to manually convert your recordset to a collection of POJO's then use Jackson to generate the JSON.
However, there are loads of frameworks that make this easier for you to achieve.
What Java framework are you using as that will constrain your future decisions to some degree? How are you reading from your DB - using JDBC API or using an ORM or other library?

WebService - Overview

There's a lot of info out there for a newbie like myself when it comes to webservices, I acknowledge that.
However, most of the Google results I've seen tend to be focusing on a specific format or strategy, and all of them different to each other.
As a newbie, I am looking to get more of an overview of the various options open to me, their pros & cons... before I start committing to a specific one.
For example, I have an existing webservice created from a SQL Server source via ASP.net and this by default comes out as a DiffGram. So there are articles that tell me how to parse the diffgram data coming into my Android app, but I still do not know if the diffgram is the best option I should be using in the first place.
Should I, for example be changing my webservice to output JSON ?
Does anyone know of a 101 level tutorial or explanation out there ?
Many Thanks
DiffGram is just another type of XML format. In order to parse the XML data in Android, simply use the XMLFullParse class.
FYI: http://developer.android.com/training/basics/network-ops/xml.html
However if you just want to create a simple data exchange WebService, Json is definitely a better choice. Json is simple, lightweight, easier-to-parse and surely easier to use.
Example:
JsonObject json = new JsonObject(jsonString);
json.put("name", "Michael");
json.put("age", "18");
String name = json.opt("name");

Android sync data to internat storage with Retrofit Service

I want to have some data stored in Device in order my application to work offline. They are plain java objects that are returned from a JSON web service. I use retrofit + GSON . The issue is how to store them.
WHAT I have tried
Tried to use Serializable interface at my java classes and during my sync() method when I fetch them from webservice I store them at a file. Performance is a bit poor at slow devices during sync. Not much but it is an issue.
WHAT I attempted
I attemted to store JSON from Response Retrofit. However it seems a bit of pain. Because it doesnt return as string the result but as InputStream. Then I have to convert back again.
WHAT I didnt do
I didnt try SQLite and any ORM. Seems overkill to me for 7 simple list of readonly List of objects. And I guess that performance is going to suffer more.
In IOS core data is easy to achieve this out of the box. Is there a solution for this in android ?
Best approach to this is to write the JSON out to a file using one of the near infinite number of free libraries or code samples, such as: http://www.mkyong.com/java/json-simple-example-read-and-write-json.

Categories

Resources