Wednesday, 26 September 2018

Restlet example

https://stackoverflow.com/questions/19341019/how-to-convert-a-json-type-input-of-a-restlet-request-to-a-pojo



@Put
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Device b(Device device) {
    // Do something with the POJO!!!
    return device;
}

Tuesday, 25 September 2018

throw exception in php 7

<?php
echo 'Current PHP version: ' . phpversion();
try {
    $num=1;
    echo $num;
    if($num) {
    throw new Exception("This is an exception");
    }
} catch(Throwable $e) {

    echo $e->getFile();
}

?>

Monday, 24 September 2018

How to remove repeated elements from ArrayList?

https://beginnersbook.com/2014/10/how-to-remove-repeated-elements-from-arraylist/

java read json file

https://crunchify.com/how-to-read-json-object-from-file-in-java/



import java.io.FileReader;
import java.util.Iterator;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
/**
* @author Crunchify.com
*/
public class Main {
    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        JSONParser parser = new JSONParser();
        try {
            Object obj = parser.parse(new FileReader(
                    "./sample.json"));
            JSONObject jsonObject = (JSONObject) obj;
            String name = (String) jsonObject.get("Name");
            String author = (String) jsonObject.get("Author");
            JSONArray companyList = (JSONArray) jsonObject.get("Company List");
            System.out.println("Name: " + name);
            System.out.println("Author: " + author);
            System.out.println("\nCompany List:");
            Iterator<String> iterator = companyList.iterator();
            while (iterator.hasNext()) {
                System.out.println(iterator.next());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
{
    "Name": "crunchify.com",
    "Author": "App Shah",
    "Company List": [
        "Compnay: eBay",
        "Compnay: Paypal",
        "Compnay: Google"
    ],
    "ERR404":{
      "errorCode":"404",
      "message":"requested file not found"
    }
}