Skip to content

Instantly share code, notes, and snippets.

@Ikhiloya
Created June 15, 2020 15:33
Show Gist options
  • Save Ikhiloya/eda6a397fa78a345702f3d2589dd3021 to your computer and use it in GitHub Desktop.
Save Ikhiloya/eda6a397fa78a345702f3d2589dd3021 to your computer and use it in GitHub Desktop.
{
"type": "",
"project_id": "",
"private_key_id": "",
"private_key": "",
"client_email": "",
"client_id": "",
"auth_uri": "",
"token_uri": "",
"auth_provider_x509_cert_url": "",
"client_x509_cert_url": ""
}
@FrankDupree
Copy link

FrankDupree commented Jun 15, 2020

package firebase.codeniro;


import java.io.File;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;


public class App {

	public static void main(String[] args) {
		
		File f = new File("firebaseconfig.json");
		if(f.exists() && !f.isDirectory()) { 
		    // do anything here
		}else {
			//lets create it
			fire firebaseConfig = new fire();
			firebaseConfig.setClient_email("frank@yahoo");
			
			// Creating Object of ObjectMapper define in Jakson Api 
	        ObjectMapper Obj = new ObjectMapper(); 
	        try {
	        	  String json = Obj.writeValueAsString(firebaseConfig);
	        	  System.out.println("ResultingJSONstring = " + json);
	        	  //System.out.println(json);
	        	} catch (JsonProcessingException e) {
	        	   e.printStackTrace();
	        	}
		}

	}

}

@FrankDupree
Copy link

package firebase.codeniro;


public class fire {
	 private String type;
	 private String project_id;
	 private String private_key_id;
	 private String private_key;
	 private String client_email;
	 private String client_id;
	 private String auth_uri;
	 private String token_uri;
	 private String auth_provider_x509_cert_url;
	 private String client_x509_cert_url;


	 // Getter Methods 

	 public String getType() {
	  return type;
	 }

	 public String getProject_id() {
	  return project_id;
	 }

	 public String getPrivate_key_id() {
	  return private_key_id;
	 }

	 public String getPrivate_key() {
	  return private_key;
	 }

	 public String getClient_email() {
	  return client_email;
	 }

	 public String getClient_id() {
	  return client_id;
	 }

	 public String getAuth_uri() {
	  return auth_uri;
	 }

	 public String getToken_uri() {
	  return token_uri;
	 }

	 public String getAuth_provider_x509_cert_url() {
	  return auth_provider_x509_cert_url;
	 }

	 public String getClient_x509_cert_url() {
	  return client_x509_cert_url;
	 }

	 // Setter Methods 

	 public void setType(String type) {
	  this.type = type;
	 }

	 public void setProject_id(String project_id) {
	  this.project_id = project_id;
	 }

	 public void setPrivate_key_id(String private_key_id) {
	  this.private_key_id = private_key_id;
	 }

	 public void setPrivate_key(String private_key) {
	  this.private_key = private_key;
	 }

	 public void setClient_email(String client_email) {
	  this.client_email = client_email;
	 }

	 public void setClient_id(String client_id) {
	  this.client_id = client_id;
	 }

	 public void setAuth_uri(String auth_uri) {
	  this.auth_uri = auth_uri;
	 }

	 public void setToken_uri(String token_uri) {
	  this.token_uri = token_uri;
	 }

	 public void setAuth_provider_x509_cert_url(String auth_provider_x509_cert_url) {
	  this.auth_provider_x509_cert_url = auth_provider_x509_cert_url;
	 }

	 public void setClient_x509_cert_url(String client_x509_cert_url) {
	  this.client_x509_cert_url = client_x509_cert_url;
	 }
	}

@FrankDupree
Copy link

<dependencies>
	<dependency>
	    <groupId>com.fasterxml.jackson.core</groupId>
	    <artifactId>jackson-databind</artifactId>
	    <version>2.9.8</version>
	</dependency>
</dependencies>

@Ikhiloya
Copy link
Author

Thanks @FrankDupree. I'll implement it and let you know the outcome.

@Ikhiloya
Copy link
Author

Thanks @FrankDupree.It's working fine now.

I converted the json string to inputstream using Apache commons IOUtils:
IOUtils.toInputStream(json)

then passed it unto the Firebase Storage initialization code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment