Instagram / ig-json-parser

Fast JSON parser for java projects
https://instagram-engineering.com/fast-auto-generated-streaming-json-parsing-for-android-ab8e7be21033
MIT License
1.32k stars 124 forks source link

Proper documentation + Wiki #5

Closed mradzinski closed 10 years ago

mradzinski commented 10 years ago

After going through the demo and unit test projects it took me almost 3 hours to realize how to make this to work. The current documentation only talks about annotating classes and misses consumption and generation of JSON. Proper documentation + Wiki is a must.

jacobtabak commented 10 years ago

Seconded,

red text

Is this normal? I realize the annotation processor is looking for that __JsonHelper suffix, but the fact that it shows up as a compiler error in the IDE is very confusing.

ttung commented 10 years ago

The .java files are generated by running the compiler. Once that's happened once, the errors should go away.

jacobtabak commented 10 years ago

It's very strange... I've used a lot of annotation processing tools with generated classes and normally the errors do go away once the build succeeds. But in this case, I am able to run / debug and the symbols are never resolved. If I change the __JsonHelper to something else, then the build fails.

ttung commented 10 years ago

@jacobtabak I changed where the generated sources are placed in https://github.com/Instagram/ig-json-parser/commit/0a822b38c6d241c5c56381dc51c6ba0604cca56a. you may need to reload the project, but I can now see the generated sources in android studio.

apologies; we don't use android studio/gradle internally, so there is a bit of a learning curve in getting things to play nicely with these tools. :)

jacobtabak commented 10 years ago

Much better now, I can step through and see the generated code now.

ttung commented 10 years ago

I updated the README with:

  1. Information about how to include the library using Maven.
  2. An example of how to invoke the generated code.

There is also an entirely standalone sample project in https://github.com/Instagram/ig-json-parser/tree/master/maven-example

ignaciod commented 10 years ago

Sorry for my ignorance, but i don't use maven very often, so i'm unable to import any of the projects in this repository into eclipse. I've m2e plugin and can't get the project imported. What should i do? I'm very fond on using this Json parser library.

iNoles commented 10 years ago

When I look at build.gradle, It is not setup to be android library at all. It expects you to build it for getting jar files.

TommyVisic commented 10 years ago

@iNoles I was able to get it running by looking at the maven-example module that ttung mentioned above. As of right now, it looks like the JSON models need to be in their own module. That module's build.gradle file needs to look like the one in the readme. Your Android module then needs to declare it as a dependency (e.g. compile project(":app:igmodel") in its own build.gradle). It looks like the reason for this is the code generation is being kicked off with a method from the Java plugin, and this plugin isn't compatible with the Android plugin. I might be making that up though.

Also it looks like Android Studio needs to be building with at least Java 1.7 and not Java 1.6.

ttung commented 10 years ago

@ignaciod I recommend you just download the jars from https://oss.sonatype.org/content/repositories/releases/com/instagram/ig-json-parser-processor/0.0.3/ig-json-parser-processor-0.0.3.jar. You will have to enable the annotation processor for your project in Eclipse (you can probably just google for those directions).

ttung commented 10 years ago

@TommyVisic Conceptually, there is no reason why it shouldn't work w/ the android plugin. I'll need to investigate that though. Internally, we always keep the model classes in a separate package because the fields must be package-visible, and we don't want direct accesses.

TommyVisic commented 10 years ago

That makes sense about the package-visible issue.

FYI, when attempting to apply both plugins, Gradle reports: Error:The 'java' plugin has been applied, but it is not compatible with the Android plugins.

ttung commented 10 years ago

Yeah, you can't apply both plugins. What I meant was: It might not be compatible at the moment, but I don't think it's fundamentally incompatible. :)

ttung commented 10 years ago

I'm going to close this issue because it's become a dumping ground for various issues.

ttung commented 10 years ago

Opening a new "documentation + wiki" issue as https://github.com/Instagram/ig-json-parser/issues/12