{{ !articles[0].partner.isSponsoringArticle ? "Platinum" : "Portal" }} Partner

Read & Recognize Barcode from External Image URL in Java Applications

This technical tip allows developers to read barcode from external image URL  using Saaspose.BarCode REST API in your Java applications. Some important steps for performing this task is to build URI for reading barcode, sending the request to Saaspose server, parse and Deserializes the JSON to an object and display the value and type of all the recognized barcodes.

//build URI to read barcode
	    //type:  Codabar, Code11, Code128 and Code39Extended etc.
            String strURI = "http://api.saaspose.com/v1.0/barcode/recognize?type=QR&url=http://upload.wikimedia.org/wikipedia/commons/c/ce/WikiQRCode.png";
            // Send the request to Saaspose server
            InputStream responseStream = ProcessCommand(Sign(strURI), "POST");
            // Read the response
            String strJSON = StreamToString(responseStream);
            //Parse and Deserializes the JSON to a object. 
            RecognitionResponse barcodeRecognitionResponse = gson.fromJson(strJSON,RecognitionResponse.class);
	    List barcodes = barcodeRecognitionResponse.getBarcodes();
            // Display the value and type of all the recognized barcodes
	    for (RecognizedBarCode barcode : barcodes)
	        System.out.println("Codetext: " + barcode.BarcodeValue() + "\nType: " + barcode.getBarcodeType());

	    \\Here is the RecognitionResponse class
	    public class RecognitionResponse extends BaseResponse
	        private List Barcodes ;
	        public List getBarcodes(){return Barcodes;}

	    \\Here is the RecognizedBarCode class	    
	    public class RecognizedBarCode
	        private String BarcodeType ;
	        private String BarcodeValue;
	        public String getBarcodeType(){return BarcodeType;}
	        public String BarcodeValue(){return BarcodeValue;}

	    \\Here is the BaseResponse class	    
	    public class BaseResponse 
	        public BaseResponse() { }
	        private String Code;
	        private String Status;
	        public String getCode(){return Code;}
	        public String getStatus(){return Status;}
	        public void  setCode(String temCode){ Code=temCode;}
	        public void setStatus(String temStatus){ Status=temStatus;}
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks