8

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?

Marian Paździoch
  • 8,813
  • 10
  • 58
  • 103
  • Did you add the dependency in your Grandle? You might want to add `javax.annotation:jsr250-api:1.0` if you have not done so. Check `[this](http://mvnrepository.com/artifact/javax.annotation/jsr250-api/1.0) – ishmaelMakitla May 05 '16 at 09:17
  • I've found similar http://stackoverflow.com/questions/9650808/android-javax-annotation-processing-package-missing and https://github.com/codepath/android_guides/wiki/Consuming-APIs-with-Retrofit. – Marian Paździoch May 09 '16 at 12:21
  • So, did you resolve your problem yet? – ishmaelMakitla May 09 '16 at 13:07
  • 1
    Lets take this out in the next release: https://github.com/joelittlejohn/jsonschema2pojo/issues/577 – joelittlejohn May 23 '16 at 20:27

2 Answers2

8

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.

Lalo
  • 118
  • 4
5

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! :-)

Tomasz Dzieniak
  • 2,765
  • 3
  • 24
  • 42