Thursday, April 29, 2021

Avsc to Pojo generate with maven project

Avro schemas are defined using JSON and let see how we can generate POJO. Here I have used maven and we can play the same with gradle also. 



Maven Dependencies

The below dependencies need to add.


We can provide the source directory and output directory directly into maven. So that we can avoid some boilerplate code in java class.





After set upping this pom, now you can place your avsc file into the methined location the pom.xml. Once you place this execute the maven command which is mvn generate-sources. No the genearting from schema to pojo process will happen. After that we have play aroung our POJO like setting data etc.,. 

Now the project structure is below format. It may differ in eclipse. I am using intellij.



Dont create entity manually. It will be generated automatically. Now its time to write final code here.





Now just run the above program and get the below output. 



From the above output you can get all details. Thats it. Have fun...

Tuesday, April 30, 2019

angular proxy config json not redirected to spring

we may face this error, when we try to hit from angular UI to back end java(Spring etc.,). The problem is with angular proxy conf json file. 

The configuration (Sample )should be ,

{
  "/api": {
    "target": "http://url.com",
    "secure": false,
    "changeOrigin": true,
    "pathRewrite": {"^/api" : ""}
  }
}

Here, "changeOrigin": true, is not mandatory if you are running in local host. means, both Cline and server both are running in same machine. But if it is different host, then changeOrigin is must. However we should need this at final production. So better set now itself.

Monday, April 8, 2019

The default Activity not found

Error : The default activity not found.

Solution:

1. Are you sure , your main activity is declared in Manifest xml ? If not , please declare and run app. It will work. Make sure only main activity name you can change. Other like Intent filter, you shoul not touch.

2. If above solution is not workout, try Run -> Edit Config-> Choose your correct activity or define default activity.

3. If above also not workout like you defined everything well, but still error coming. Please do File -> Invalidate cache and restart.

4. If above also not work, this is the final solution File -> Sync with Gradle. Definitely It will work.


Tuesday, April 2, 2019

Must declare the scalar variable @Po ...

We may get this sql exception error when dealing with sql query. I also faced this and after a big analysis , found two causes.

1. We did DB migration - So your case check any migration (version changes) happened.

2. Second issue - Syntax issue like space , name mismatch, declaring is wrong.


Thursday, March 21, 2019

Creating an array of objects in Java



1. Declaration
 A[ ] arr = new A[4];


 2. Initializing the Objects 

 arr[0] = new A();
 arr[1] = new A();
 arr[2] = new A();
 arr[3] = new A();

 3. Initializing via loop

 for( int i=0; i<4; i++ )
 arr[i] = new A();
 
 
 
 By java 8
 A[] a = Stream.generate(() -> new A()).limit(4).toArray(A[]::new);

Wednesday, February 20, 2019

Could not find method versioncode () for arguments 1.1 on defaultconfig

This problem came, when I tried to upload an apk to playstore with version changes. Means, I launched my second version and got this error.

Solution:

Go to you build.gradle(app) and make changes like below. It will work.
minSdkVersion 15targetSdkVersion 26versionCode 2.0.toInteger() // This is what I changed
versionName "2.0"

Thursday, December 6, 2018

Class not found when running test case during gradle build

Problem:

I got the exception when I run the test case, which is using the generated WSDL source file, and got "Class not found exception" . Because my test case not able to find the genearted source code from WSDL.


Solution:

I added the below line gradle and its working fine.

sourceSets.test.java.srcDirs = ['.apt_generated/xxx,'src/test/java']