Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

**EXPERIMENTAL** Support Parcelable types for Android #127

Closed
joelittlejohn opened this issue Oct 16, 2013 · 16 comments
Closed

**EXPERIMENTAL** Support Parcelable types for Android #127

joelittlejohn opened this issue Oct 16, 2013 · 16 comments
Milestone

Comments

@joelittlejohn
Copy link
Owner

This came up on the mailing list, and sounds like it might be very useful for a lot of people:

https://groups.google.com/forum/#!topic/jsonschema2pojo-users/IX0g58VAS58

More details:

http://developer.android.com/reference/android/os/Parcelable.html

@joelittlejohn
Copy link
Owner Author

Draft implementation is complete, feedback welcome:

https://github.com/joelittlejohn/jsonschema2pojo/tree/parcelable

Note, this has only been tested with robolectric.

@joelittlejohn
Copy link
Owner Author

It would be helpful if someone could test this. Simply build a snapshot from this branch and turn on JSR-303 annotations to try out the Parcelable support:

<includeJsr303Annotations>true</includeJsr303Annotations>

(I've reused this config property for now, will create a new one when this appears to be working)

EDIT: I've made a proper config option now, use <parcelable>true</parcelable> to test this.

@jsuksl
Copy link
Contributor

jsuksl commented Dec 16, 2014

I found that the code lines below generate Parcelable classes which have the annotations("javax.validation.constraints.NotNull", "javax.validation.Valid" ) not available on the Android runtime

ruleFactory.getValidRule().apply(nodeName, node, field, schema);
((JFieldVar) generatableType).annotate(NotNull.class);

@joelittlejohn
Copy link
Owner Author

Are you able to include the javax.validation/validation-api jar? I really need to create a dedicated config argument for parcelable so that it can be tested more easily.

@jsuksl
Copy link
Contributor

jsuksl commented Dec 18, 2014

Good to hear your feedback.
As you suggested, adding 'javax.validation:validation-api:1.0.0.GA' to my build.grade resolves build errors.

compile 'javax.validation:validation-api:1.0.0.GA'

I hope to see new release with Parcelable support is available on maven repository soon.

@jsuksl
Copy link
Contributor

jsuksl commented Dec 18, 2014

BTW, would you consider to introduce new option(other than "includeJsr303Annotations") for Android Parcelable types support when it comes to release this in the future?
I think that includeJsr303Annotations and "Android Parcelable types support" are two different categories of features that deserve separate config options .

@joelittlejohn
Copy link
Owner Author

I've just rebased the parcelable branch against master and added a proper 'parcelable' config option. If anyone would like to test the parcelable support, just build a snapshot from this branch:

https://github.com/joelittlejohn/jsonschema2pojo/tree/parcelable

Then if you're using Maven, activate the parcelable support like:

<parcelable>true</parcelable>

gradle, CLI, Ant etc have an equivalent config option.

@joelittlejohn
Copy link
Owner Author

@jsuksl @premnirmal @LOG-TAG if you can give this a test and provide some feedback, this would be very helpful. I don't really know if the current implementation approach will work or not.

@jsuksl
Copy link
Contributor

jsuksl commented Mar 9, 2015

@joelittlejohn https://github.com/joelittlejohn/jsonschema2pojo/tree/parcelable works fine. BTW, I see jsonschema2pojo-maven-plugin build fails.

@joelittlejohn
Copy link
Owner Author

Thanks @jsuksl! Could you give me some details of how you tested this? What kind of object did you parcel and what environment did you use to test this?

Also, I don't see any problems with the build when I run mvn clean verify on the parcelable branch. What build failure did you see?

@jsuksl
Copy link
Contributor

jsuksl commented Mar 10, 2015

I used jsonschema2pojo built from https://github.com/joelittlejohn/jsonschema2pojo/tree/parcelable to convert json schema files(30+) to POJO classes which contains information for UI components. few of the POJO classes are used as a parameter value( "http://developer.android.com/reference/android/content/Intent.html#putExtra(java.lang.String, android.os.Parcelable)" ) and can be written to and restored from Parcel successfully.

I encountered the errors below when I run mvn clean verify

[INFO] Reactor Summary:
[INFO] 
[INFO] jsonschema2pojo ................................... SUCCESS [53.950s]
[INFO] jsonschema2pojo-core .............................. SUCCESS [20.446s]
[INFO] jsonschema2pojo-ant ............................... SUCCESS [0.758s]
[INFO] jsonschema2pojo-cli ............................... SUCCESS [4.502s]
[INFO] jsonschema2pojo-gradle-plugin ..................... SUCCESS [6.990s]
[INFO] jsonschema2pojo-maven-plugin ...................... FAILURE [5.623s]
[INFO] jsonschema2pojo-integration-tests ................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:34.933s
[INFO] Finished at: Tue Mar 10 10:38:07 JST 2015
[INFO] Final Memory: 34M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (default-testCompile) on project jsonschema2pojo-maven-plugin: Compilation failure: Compilation failure:
[ERROR] /Users/jsuk/Documents/play_ground/jsonschema2pojo/jsonschema2pojo-maven-plugin/src/test/java/org/jsonschema2pojo/maven/MatchPatternsFileFilterTest.java:[49,8] cannot find symbol
[ERROR] symbol  : method assertThat(java.lang.String,java.util.List<java.io.File>,org.hamcrest.Matcher<java.lang.Iterable<java.lang.Object>>)
[ERROR] location: class org.jsonschema2pojo.maven.MatchPatternsFileFilterTest
[ERROR] /Users/jsuk/Documents/play_ground/jsonschema2pojo/jsonschema2pojo-maven-plugin/src/test/java/org/jsonschema2pojo/maven/MatchPatternsFileFilterTest.java:[67,8] cannot find symbol
[ERROR] symbol  : method assertThat(java.lang.String,java.util.List<java.io.File>,org.hamcrest.Matcher<java.lang.Iterable<java.lang.Object>>)
[ERROR] location: class org.jsonschema2pojo.maven.MatchPatternsFileFilterTest
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :jsonschema2pojo-maven-plugin

@joelittlejohn
Copy link
Owner Author

Hmm, I think the assertThat call is confusing the compiler as the varargs are making it ambiguous. I don't see this error when I run the build though. Could you let me know your OS, JDK version and Maven version?

@jsuksl
Copy link
Contributor

jsuksl commented Mar 10, 2015

Here you are

Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-18 00:22:22+0900)
Maven home: /usr/local/Cellar/maven/3.1.1/libexec
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"

@jsuksl
Copy link
Contributor

jsuksl commented Mar 10, 2015

The errors have been resolved after letting maven use JDK 1.7

[INFO] 
[INFO] --- maven-failsafe-plugin:2.7.2:verify (verify) @ jsonschema2pojo-integration-tests ---
[INFO] Failsafe report directory: /Users/jsuk/Documents/play_ground/jsonschema2pojo/jsonschema2pojo-integration-tests/target/failsafe-reports
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] jsonschema2pojo ................................... SUCCESS [27.635s]
[INFO] jsonschema2pojo-core .............................. SUCCESS [5.232s]
[INFO] jsonschema2pojo-ant ............................... SUCCESS [0.860s]
[INFO] jsonschema2pojo-cli ............................... SUCCESS [3.106s]
[INFO] jsonschema2pojo-gradle-plugin ..................... SUCCESS [6.553s]
[INFO] jsonschema2pojo-maven-plugin ...................... SUCCESS [20.631s]
[INFO] jsonschema2pojo-integration-tests ................. SUCCESS [33.722s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:38.148s
[INFO] Finished at: Wed Mar 11 00:20:56 JST 2015
[INFO] Final Memory: 91M/545M
[INFO] ------------------------------------------------------------------------
Mac-b8e8560fa544:jsonschema2pojo jsuk$ mvn -v
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-18 00:22:22+0900)
Maven home: /usr/local/Cellar/maven/3.1.1/libexec
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"

@joelittlejohn
Copy link
Owner Author

I've included 'experimental' support for this in master. People can give this a try and provide some feedback if they have problems.

@joelittlejohn joelittlejohn added this to the 0.4.11 milestone Apr 15, 2015
@joelittlejohn joelittlejohn changed the title Support Parcelable types for Android **EXPERIMENTAL** Support Parcelable types for Android Apr 15, 2015
@jsuksl
Copy link
Contributor

jsuksl commented Apr 16, 2015

thanks!

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

No branches or pull requests

2 participants