Gson parsing a Json file - java

i am trying to parse the following json file in java with gson:
So , I am trying to retrieve only the issues into a list of Issue. I have the following class to store the issue information:
But i got an error.. I am trying to get with the following but I think that i am so lost with this ( i am learning about this ) and i dont understand the error
any idea of how to do this? thank you so much!

obj.get("issues")
will actually return a List Object, and not an Issue Object. You need to change the second parameter accordingly.

Related

LibGDX: Cannot load a json file from assets folder

I have a json file with data for all the tiles in my game that I store in the assets folder. I try to access and parse it using TileList dataList = json.fromJson(TileList.class, Gdx.file.internal("map-elements/tiles/tiles.json")). This works fine for the desktop version but on the html version, after converting with gwt, I get these errors:
GwtApplication: exception: Error reading file: map-elements/tiles/tiles.json
Error reading file: map-elements/tiles/tiles.json
Couldn't find Type for class 'net.vediogames.archipelo.world.tiles.TileList'
TileList is a simple object that contains an array of TileData which can then be converted into Tile objects. I did it this way to make the json parsing easy.
The solution to the json error is simple. Instead of passing the FileHandle into the json parser, pass the string from the file like this:
TileList dataList = json.fromJson(TileList.class, Gdx.file.internal("map-elements/tiles/tiles.json").readString());
In the end, all I needed to do to solve that issue is add .readString(). As for the Couldn't find Type for class 'net.vediogames.archipelo.world.tiles.TileList' error, I also found a solution but it is more complicated.
JavaScript handles class references differently than Java. So I was not able to use TileList.class without first registering it so LibGDX can generate a Reflection. What I needed to do was add this line into my *.gwt.xml files:
<extend-configuration-property name="gdx.reflect.include" value="net.vediogames.archipelo.world.tiles.TileList" />
If you want a full tutorial about how reflection works and how to include packages or exclude, please view the official LibGDX tutorial here.
Your solution was not working for me, I still got the same error. After some hours of testing I got it to work, using your suggestions and by using the ClassReflection instead of referencing the class itself.
Your example:
TileList dataList = json.fromJson(TileList.class, Gdx.file.internal("map-elements/tiles/tiles.json").readString());
looks in my working code like:
TileList dataList = (TileList) json.fromJson(ClassReflection.forName(TileList.class.getName()), Gdx.file.internal("map-elements/tiles/tiles.json").readString());
This is quite a pain in the a.. but I'm glad it is finally working now.

Issue when fetching Document information from a Record Filenet

I am facing a issue where I am not able to get the document information associated with the record.
The line below is used to get a particular record,
com.ibm.jarm.api.core.Record r = RMFactory.Record.fetchInstance(jarmFPOS, "{AE10E0F1-323F-4445-A529-78F744E8D3E4}", null);
Now that I have a record object I need to fetch the document information such as DocId, DocTitle, DocOwner etc..I know that the required information is stored in a property called as “RecordedDocuments” or we can use RMProperty.DOCUMENT_LINK from which we can get the value. I am using something like below.
Object obj3 = (Object) r.getProperties().get(RMProperty.DOCUMENT_LINK).getObjectValue();
My issue is here. I am not able to get the values from the Object. I tried typecasting it to a document object but no luck. I keep on getting typecasting error. Can anyone please help me how to get the desired output.
Thanks.
The Link object would not be a document directly... I'm not very familiar with RM APIs, more with CE APIs, but it would probably be an implementation of the RMLink interface.
What I usually do in such a case is print out the java class name of the object (obj3.getClass().getName()) and that would give you a good indication on which API object you can use.
May be because it was a list and not a Document that fails the casting? Try what polonoko told you and print the className.
Or try this code :)
List<com.filenet.api.core.Document> doc = (List<com.filenet.api.core.Document>) r.getProperties().get(RMProperty.DOCUMENT_LINK).getObjectValue();

Getting Name Value JSON in PIG

Hi guys i just started doing pig, I was wondering if JsonLoader is capable of parsing all value inside json.
for example:
{"food":"Tacos", "person":"Alice", "amount":3}
and i need to get "food" stored as a relation in chararray and "Tacos" which is the value of "food" to another relation.
after reading many tutorial and documentation, i havent found a built in method to do so.
does it mean that the only solution to this is through UDF?
thanks a lot!
I found the answer that is to use external jar from twitter.
register 'hdfs:/udf/elephant-bird-pig-4.10.jar';
register 'hdfs:/udf/elephant-bird-core-4.10.jar';
register 'hdfs:/udf/elephant-bird-hadoop-compat-4.10.jar';
register 'hdfs:/udf/json-simple-1.1.1.jar';
test.json
{"food":"Tacos", "person":"Alice", "amount":3}
script:
A = LOAD 'hdfs:/test.json' USING com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad') AS (json:map[]);
DUMP A;
and the output that i wanted is:
([amount#3,food#Tacos,person#Alice])
Thanks!
input- pig.json
{"food":"Tacos", "person":"Alice", "amount":3}
script
A = LOAD '/home/kishore/Data/Pig/pig.json' USING JsonLoader('food:chararray,person:chararray,amount:int');
B = foreach A generate food,person,amount;
Dump B;
output
(Tacos,Alice,3)

Getting "JSONObject["myKey"] is not a JSONArray."

I have a bit of code that has been working for years
JSONObject variableData = new JSONObject(request.getParameter("VARIABLE_DATA"));
JSONArray companies = variableData.getJSONArray("COMPANIES");
and today, I get the following error:
JSONObject["COMPANIES"] is not a JSONArray.
I have stopped the code prior to executing the getJSONArray() call and looked into variableData. Here is what I find:
{"COMPANIES":[{"COMPANY":"2"}]}
To me, this looks like a valid JSONArray to be pulled from a valid JSONObject, so I'm flummoxed and looking for help. Thanks.
your piece of code works fine when using org.json-20120521.jar. I think there is something wrong with the jar you are using.
But "COMPANIES":[{"COMPANY":"2"}] is not a valid json. Other question that I would ask is the exception reproducible? Did you get this data from exact same request that produced the exception? Is there a chance that your server got corrupted data? Try to write a unit test that covers this case and check were it takes you.

Arcgis Map : PictureMarkerSymbol

Hie everybody, i am trying to make a PictureSymbolMarker in my arcgis map..
However i am facing some problems in it. i went to esri website [ http://blogs.esri.com/esri/arcgis/2012/02/03/esri-picture-marker-symbol-generator-for-javascript-developers/ ] to get a pin url .
When i tried to implement it in my codes,
i received error .
This is how i put it together
From
`//Marker
SimpleMarkerSymbol resultSymbol = new SimpleMarkerSymbol(Color.RED,
20, SimpleMarkerSymbol.STYLE.CIRCLE);`
To
`SimpleMarkerSymbol resultSymbol = new SimpleMarkerSymbol
({"angle":0,"xoffset":0,"yoffset":12,"type":"esriPMS",
"url":"http://static.arcgis.com/images/Symbols/Basic/RedStickpin.png",
"contentType":"image/png","width":24,"height":24});`
But after implementing that codes, i received errors. .. Anybody have face the same problem and are enable to troubleshoot it?
Thanks in Advance
your issue is that you are using JSON for a PictureMarkerSymbol and initializing a SimpleMarkerSymbol which will never work. Try to do like this.
var resultSymbol = new esri.symbol.PictureMarkerSymbol
({"angle":0,"xoffset":0,"yoffset":12,"type":"esriPMS",
"url":"http://static.arcgis.com/images/Symbols/Basic/RedStickpin.png",
"contentType":"image/png","width":24,"height":24});
You're using JavaScript object notation (JSON) syntax in your Java code for Android. It won't work.
#azmuhak is on the right track though. You need to create a PictureMarkerSymbol instead of a SimpleMarkerSymbol. But you need to do it the Android way, not the JavaScript way.
Here's some sample code for creating a PictureMarkerSymbol, creating a GraphicsLayer, adding the GraphicsLayer to the map, and adding a new Graphic to the GraphicsLayer (run this code after the map is loaded, maybe using MapView.setOnStatusChangedListener):
PictureMarkerSymbol pms = new PictureMarkerSymbol(
"http://static.arcgis.com/images/Symbols/Basic/RedStickpin.png");
pms.setAngle(0f);
pms.setOffsetX(0f);
pms.setOffsetY(12f);
GraphicsLayer graphicsLayer = new GraphicsLayer();
mMapView.addLayer(graphicsLayer);
graphicsLayer.addGraphic(new Graphic(new Point(12, 34), pms));
Side note: it is possible in Android to parse a JSON string to make a PictureMarkerSymbol. But in this case, my sample code is easier and less error-prone.

Categories

Resources