Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POJOs generated by jsonschema2pojo have annotation which Android Studio doesn't understand

When I generate POJOs via http://www.jsonschema2pojo.org/ I get something like this:

import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

@Generated("org.jsonschema2pojo")
public class Name {
    //...
}

But Android Studio does not recognize javax.annotation.Generated and I have to remove two lines of code

import javax.annotation.Generated;

and

@Generated("org.jsonschema2pojo")

form every POJO and this is a pain. Is there a way to suppress http://www.jsonschema2pojo.org/ from adding that annotation?

like image 792
Marian Paździoch Avatar asked May 05 '16 09:05

Marian Paździoch


2 Answers

If you are using Gradle, go to your build.gradle file inside your 'app/' folder, and inside dependencies {...} add:

compile 'org.glassfish:javax.annotation:10.0-b28'

Then rebuild the project. That should fix it.

like image 169
Lalo Avatar answered Nov 14 '22 04:11

Lalo


You can always ask Gradle to remove redundant lines before compilation (automatically for you):

task cleanupPojo {
    def trim = [
        '.*org.jsonschema2pojo.*',
        'import javax.annotation.Generated;'
    ]

    for(def text: trim) {
        ant.replaceregexp(match: text, replace: '', flags: 's', byline: true) {
            fileset(dir: 'src', includes: '**/*.java')
        }
    }
}

Above script uses Ant's task replaceregexp to remove all occurrences of texts from trim array.

Chapeau bas continuous integration! :-)

like image 39
Tomasz Dzieniak Avatar answered Nov 14 '22 04:11

Tomasz Dzieniak