diff --git a/.gitignore b/.gitignore index 84d53f7..a280531 100644 --- a/.gitignore +++ b/.gitignore @@ -1,33 +1,29 @@ -# Created by https://www.gitignore.io/api/osx,java,gradle,windows,intellij +# Created by https://www.gitignore.io/api/java,gradle,intellij,macos,windows ### Intellij ### # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff: -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/dictionaries +.idea/workspace.xml +.idea/tasks.xml # Sensitive or high-churn files: -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.xml -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml +.idea/dataSources/ +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml # Gradle: -.idea/**/gradle.xml -.idea/**/libraries - -# CMake -cmake-build-debug/ +.idea/gradle.xml +.idea/libraries # Mongo Explorer plugin: -.idea/**/mongoSettings.xml +.idea/mongoSettings.xml ## File-based project format: *.iws @@ -43,9 +39,6 @@ cmake-build-debug/ # JIRA plugin atlassian-ide-plugin.xml -# Cursive Clojure plugin -.idea/replstate.xml - # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties @@ -60,16 +53,9 @@ fabric.properties # .idea/misc.xml # *.ipr -# Sonarlint plugin -.idea/sonarlint - ### Java ### -# Compiled class file *.class -# Log file -*.log - # BlueJ files *.ctxt @@ -80,14 +66,11 @@ fabric.properties *.jar *.war *.ear -*.zip -*.tar.gz -*.rar # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -### OSX ### +### macOS ### *.DS_Store .AppleDouble .LSOverride @@ -95,6 +78,7 @@ hs_err_pid* # Icon must end with two \r Icon + # Thumbnails ._* @@ -151,4 +135,4 @@ gradle-app.setting # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 # gradle/wrapper/gradle-wrapper.properties -# End of https://www.gitignore.io/api/osx,java,gradle,windows,intellij \ No newline at end of file +# End of https://www.gitignore.io/api/java,gradle,intellij,macos,windows \ No newline at end of file diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 0000000..5dfbdec --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index f1e63dd..dc635d8 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -4,10 +4,8 @@ - - - - + + \ No newline at end of file diff --git a/.idea/google-java-format.xml b/.idea/google-java-format.xml deleted file mode 100644 index 8b57f45..0000000 --- a/.idea/google-java-format.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml deleted file mode 100644 index dbe0e46..0000000 --- a/.idea/markdown-navigator.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml deleted file mode 100644 index 57927c5..0000000 --- a/.idea/markdown-navigator/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 635999d..0548357 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,33 +1,6 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index ed3e9fa..490ffd9 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,6 +3,8 @@ + + \ No newline at end of file diff --git a/.idea/modules/ason.iml b/.idea/modules/ason.iml index 55966a7..d73f64d 100644 --- a/.idea/modules/ason.iml +++ b/.idea/modules/ason.iml @@ -1,44 +1,12 @@ - - - - - - - - - - - - - - + + - - - - + - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/ason_main.iml b/.idea/modules/ason_main.iml new file mode 100644 index 0000000..61047c2 --- /dev/null +++ b/.idea/modules/ason_main.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/ason_test.iml b/.idea/modules/ason_test.iml new file mode 100644 index 0000000..c925a90 --- /dev/null +++ b/.idea/modules/ason_test.iml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..fce7f71 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9aa7217 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: java +jdk: oraclejdk8 +before_script: + - chmod +x gradlew +script: + - ./gradlew check + - ./gradlew test jacocoTestReport +after_success: + - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/README.md b/README.md index 53badb5..c2576b2 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,6 @@ in the Android SDK. As we all know, those stock classes tend to be a pain. They 9. [Annotations](https://github.com/afollestad/ason#annotations) 1. [@AsonName](https://github.com/afollestad/ason#asonname) 2. [@AsonIgnore](https://github.com/afollestad/ason#asonignore) -10. [Retrofit](https://github.com/afollestad/ason#retrofit) --- @@ -55,7 +54,7 @@ The dependency is available via jCenter. ```Gradle dependencies { ... - compile 'com.afollestad:ason:[latest-version]' + compile 'com.afollestad:ason:1.4.6' } ``` @@ -66,7 +65,7 @@ Since Android includes `org.json` classes, you'll want to exclude the copies pro ```Gradle dependencies { ... - compile('com.afollestad:ason:[latest-version]') { + compile('com.afollestad:ason:1.4.6') { exclude group: 'org.json', module: 'json' } } @@ -80,7 +79,7 @@ Android, make sure you also exclude org.json as shown in the section above.* ```Gradle dependencies { ... - compile('com.afollestad:ason:[latest-version]') { + compile('com.afollestad:ason:1.4.6') { exclude group: 'com.intellij', module: 'annotations' } } @@ -92,7 +91,7 @@ dependencies { com.afollestad ason - [latest-version] + 1.4.6 pom ``` @@ -354,7 +353,7 @@ Take this JSON: "id": 2 }, { - "name": "Nina", + "name": "Waverly", "id": 1 } ] @@ -369,7 +368,7 @@ Ason ason = new Ason() .put("title", "Hello, world!") .put("participants.$0.name", "Aidan") .put("participants.$0.id", 2) - .put("participants.$1.name", "Nina") + .put("participants.$1.name", "Waverly") .put("participants.$1.id", 1); ``` @@ -428,7 +427,7 @@ Take this JSON: { "participants": { "$1": { - "name": "Nina" + "name": "Waverly" } } } @@ -473,7 +472,7 @@ We can serialize an instance as follows: ```java Person aidan = new Person(1, "Aidan"); -aidan.spouse = new Person(2, "Nina"); +aidan.spouse = new Person(2, "Waverly"); Ason ason = Ason.serialize(aidan); ``` @@ -486,7 +485,7 @@ The resulting `Ason` object is: "name": "Aidan", "spouse": { "id": 2, - "name": "Nina" + "name": "Waverly" } } ``` @@ -523,7 +522,7 @@ If you already have a `Ason` instance, you can add Java class instances into the ```java Ason ason = new Ason(); Person person1 = new Person(1, "Aidan"); -Person person2 = new Person(2, "Nina"); +Person person2 = new Person(2, "Waverly"); ason.put("person1", person); ason.put("person2", person2); @@ -539,7 +538,7 @@ This would result in: }, "person2": { "id": 2, - "name": "Nina" + "name": "Waverly" } } ``` @@ -551,7 +550,7 @@ This automatic serialization works with `AsonArray`'s too: ```java AsonArray array = new AsonArray(); Person person1 = new Person(1, "Aidan"); -Person person2 = new Person(2, "Nina"); +Person person2 = new Person(2, "Waverly"); array.add(person1, person2); ``` @@ -566,7 +565,7 @@ This would result in: }, { "id": 2, - "name": "Nina" + "name": "Waverly" } ] ``` @@ -598,7 +597,7 @@ public class Person { We can deserialize an object as follows: ```java -String input = "{\"id\":1,\"name\":\"Aidan\",\"spouse\":{\"id\":2,\"name\":\"Nina\"}}"; +String input = "{\"id\":1,\"name\":\"Aidan\",\"spouse\":{\"id\":2,\"name\":\"Waverly\"}}"; Ason ason = new Ason(input); Person person = ason.deserialize(Person.class); @@ -607,7 +606,7 @@ Person person = ason.deserialize(Person.class); There is also a static method which has the same effect: ```java -String input = "{\"id\":1,\"name\":\"Aidan\",\"spouse\":{\"id\":2,\"name\":\"Nina\"}}"; +String input = "{\"id\":1,\"name\":\"Aidan\",\"spouse\":{\"id\":2,\"name\":\"Waverly\"}}"; Ason ason = new Ason(input); Person person = Ason.deserialize(ason, Person.class); @@ -616,7 +615,7 @@ Person person = Ason.deserialize(ason, Person.class); Lastly, you can directly deserialize JSON strings: ```java -String input = "{\"id\":1,\"name\":\"Aidan\",\"spouse\":{\"id\":2,\"name\":\"Nina\"}}"; +String input = "{\"id\":1,\"name\":\"Aidan\",\"spouse\":{\"id\":2,\"name\":\"Waverly\"}}"; Person person = Ason.deserialize(input, Person.class); ``` @@ -625,7 +624,7 @@ Person person = Ason.deserialize(input, Person.class); You can deserialize JSON arrays to Java lists and arrays too: ```java -String input = "[{\"name\":\"Aidan\",\"_id\":1},{\"name\":\"Nina\",\"_id\":2}]"; +String input = "[{\"name\":\"Aidan\",\"_id\":1},{\"name\":\"Waverly\",\"_id\":2}]"; AsonArray array = new AsonArray<>(input); Person[] peopleArray = array.deserialize(Person[].class); @@ -634,7 +633,7 @@ Person[] peopleArray = array.deserialize(Person[].class); There is also static methods which have the same effect: ```java -String input = "[{\"name\":\"Aidan\",\"_id\":1},{\"name\":\"Nina\",\"_id\":2}]"; +String input = "[{\"name\":\"Aidan\",\"_id\":1},{\"name\":\"Waverly\",\"_id\":2}]"; AsonArray array = new AsonArray<>(input); Person[] peopleArray = Ason.deserialize(array, Person[].class); @@ -643,7 +642,7 @@ Person[] peopleArray = Ason.deserialize(array, Person[].class); Lastly, you can directly deserialize JSON strings: ```java -String input = "[{\"name\":\"Aidan\",\"_id\":1},{\"name\":\"Nina\",\"_id\":2}]"; +String input = "[{\"name\":\"Aidan\",\"_id\":1},{\"name\":\"Waverly\",\"_id\":2}]"; Person[] peopleArray = Ason.deserialize(input, Person[].class); ``` @@ -659,7 +658,7 @@ int[] primitiveArray = Ason.deserialize(input, int[].class); Unlike objects and arrays, deserializing lists requires a separate method: ```java -String input = "[{\"name\":\"Aidan\",\"_id\":1},{\"name\":\"Nina\",\"_id\":2}]"; +String input = "[{\"name\":\"Aidan\",\"_id\":1},{\"name\":\"Waverly\",\"_id\":2}]"; AsonArray array = new AsonArray<>(input); List peopleList = array.deserializeList(Person.class); @@ -668,7 +667,7 @@ List peopleList = array.deserializeList(Person.class); There is also a static method which has the same effect: ```java -String input = "[{\"name\":\"Aidan\",\"_id\":1},{\"name\":\"Nina\",\"_id\":2}]"; +String input = "[{\"name\":\"Aidan\",\"_id\":1},{\"name\":\"Waverly\",\"_id\":2}]"; AsonArray array = new AsonArray<>(input); List peopleList = Ason.deserializeList(array, Person.class); @@ -677,7 +676,7 @@ List peopleList = Ason.deserializeList(array, Person.class); You can deserialize strings directly: ```java -String input = "[{\"name\":\"Aidan\",\"_id\":1},{\"name\":\"Nina\",\"_id\":2}]"; +String input = "[{\"name\":\"Aidan\",\"_id\":1},{\"name\":\"Waverly\",\"_id\":2}]"; List peopleList = Ason.deserializeList(input, Person.class); ``` @@ -765,27 +764,3 @@ public class Person { } } ``` - ----- - -# Retrofit - -Ason's built in Retrofit converters let you send and receive objects with Retrofit, they are -automatically serialized or deserialized. Just add the converter factory to your Retrofit instances: - -```java -Retrofit retrofit = - new Retrofit.Builder() - ... - .addConverterFactory(new AsonConverterFactory()) - .build(); -``` - -`AsonConverterFactory` exists in a separate dependency: - -```Gradle -dependencies { - ... - compile 'com.afollestad:ason-retrofit:[latest-version]' -} -``` \ No newline at end of file diff --git a/asonapt/.gitignore b/asonapt/.gitignore deleted file mode 100644 index 84d53f7..0000000 --- a/asonapt/.gitignore +++ /dev/null @@ -1,154 +0,0 @@ - -# Created by https://www.gitignore.io/api/osx,java,gradle,windows,intellij - -### Intellij ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/dictionaries - -# Sensitive or high-churn files: -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.xml -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml - -# Gradle: -.idea/**/gradle.xml -.idea/**/libraries - -# CMake -cmake-build-debug/ - -# Mongo Explorer plugin: -.idea/**/mongoSettings.xml - -## File-based project format: -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -### Intellij Patch ### -# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 - -# *.iml -# modules.xml -# .idea/misc.xml -# *.ipr - -# Sonarlint plugin -.idea/sonarlint - -### Java ### -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -### OSX ### -*.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -ehthumbs.db -ehthumbs_vista.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk - -### Gradle ### -.gradle -/build/ - -# Ignore Gradle GUI config -gradle-app.setting - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar - -# Cache of project -.gradletasknamecache - -# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 -# gradle/wrapper/gradle-wrapper.properties - -# End of https://www.gitignore.io/api/osx,java,gradle,windows,intellij \ No newline at end of file diff --git a/asonapt/build.gradle b/asonapt/build.gradle deleted file mode 100644 index ad5a749..0000000 --- a/asonapt/build.gradle +++ /dev/null @@ -1,63 +0,0 @@ -apply from: "../gradle/dependencies.gradle" - -group 'com.afollestad' -version versions.publishVersion - -apply plugin: 'java' -apply plugin: 'idea' -apply plugin: 'jacoco' -apply plugin: 'com.novoda.bintray-release' - -sourceCompatibility = 1.7 - -buildscript { - apply from: "../gradle/dependencies.gradle" - - repositories { - jcenter() - } - dependencies { - classpath "com.novoda:bintray-release:$versions.bintrayRelease" - classpath "com.diffplug.spotless:spotless-plugin-gradle:$versions.spotlessPlugin" - } -} - -repositories { - mavenCentral() - jcenter() -} - -dependencies { - testCompile group: 'junit', name: 'junit', version: versions.junit - testCompile group: 'com.google.code.gson', name: 'gson', version: versions.gson - - compile group: 'org.json', name: 'json', version: versions.json - compile group: 'com.intellij', name: 'annotations', version: versions.intellij -} - -//publish { -// userOrg = 'drummer-aidan' -// groupId = 'com.afollestad' -// artifactId = 'ason-apt' -// publishVersion = versions.publishVersion -// website = 'https://github.com/afollestad/ason' -//} - -jacocoTestReport { - reports { - xml.enabled true - html.enabled false - } -} - -apply plugin: "com.diffplug.gradle.spotless" - -spotless { - java { - target "**/*.java" - trimTrailingWhitespace() - removeUnusedImports() - googleJavaFormat() - endWithNewline() - } -} diff --git a/asonapt/gradle/wrapper/gradle-wrapper.jar b/asonapt/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 92ef215..0000000 Binary files a/asonapt/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/asonapt/gradle/wrapper/gradle-wrapper.properties b/asonapt/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 31befbc..0000000 --- a/asonapt/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Sun Aug 27 16:52:41 CDT 2017 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip diff --git a/asonapt/gradlew b/asonapt/gradlew deleted file mode 100755 index 4453cce..0000000 --- a/asonapt/gradlew +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env sh - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save ( ) { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - -exec "$JAVACMD" "$@" diff --git a/asonapt/gradlew.bat b/asonapt/gradlew.bat deleted file mode 100644 index e95643d..0000000 --- a/asonapt/gradlew.bat +++ /dev/null @@ -1,84 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/asonapt/settings.gradle b/asonapt/settings.gradle deleted file mode 100644 index 1984e83..0000000 --- a/asonapt/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'asonapt' - diff --git a/asonretrofit/.gitignore b/asonretrofit/.gitignore deleted file mode 100644 index 84d53f7..0000000 --- a/asonretrofit/.gitignore +++ /dev/null @@ -1,154 +0,0 @@ - -# Created by https://www.gitignore.io/api/osx,java,gradle,windows,intellij - -### Intellij ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/dictionaries - -# Sensitive or high-churn files: -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.xml -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml - -# Gradle: -.idea/**/gradle.xml -.idea/**/libraries - -# CMake -cmake-build-debug/ - -# Mongo Explorer plugin: -.idea/**/mongoSettings.xml - -## File-based project format: -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -### Intellij Patch ### -# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 - -# *.iml -# modules.xml -# .idea/misc.xml -# *.ipr - -# Sonarlint plugin -.idea/sonarlint - -### Java ### -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -### OSX ### -*.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -ehthumbs.db -ehthumbs_vista.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk - -### Gradle ### -.gradle -/build/ - -# Ignore Gradle GUI config -gradle-app.setting - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar - -# Cache of project -.gradletasknamecache - -# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 -# gradle/wrapper/gradle-wrapper.properties - -# End of https://www.gitignore.io/api/osx,java,gradle,windows,intellij \ No newline at end of file diff --git a/asonretrofit/build.gradle b/asonretrofit/build.gradle deleted file mode 100644 index 56b6405..0000000 --- a/asonretrofit/build.gradle +++ /dev/null @@ -1,67 +0,0 @@ -apply from: "../gradle/dependencies.gradle" - -group 'com.afollestad' -version versions.publishVersion - -apply plugin: 'java' -apply plugin: 'jacoco' -apply plugin: 'com.novoda.bintray-release' - -sourceCompatibility = 1.7 - -buildscript { - apply from: "../gradle/dependencies.gradle" - - repositories { - jcenter() - } - dependencies { - classpath "com.novoda:bintray-release:$versions.bintrayRelease" - classpath "com.diffplug.spotless:spotless-plugin-gradle:$versions.spotlessPlugin" - } -} - -repositories { - mavenCentral() - jcenter() -} - -dependencies { - testCompile group: 'junit', name: 'junit', version: versions.junit - testCompile group: 'com.google.code.gson', name: 'gson', version: versions.gson - testCompile "io.reactivex.rxjava2:rxjava:$versions.rxJava2" - testCompile "com.squareup.retrofit2:adapter-rxjava2:+" - testCompile "com.google.truth:truth:$versions.truth" - - implementation group: 'org.json', name: 'json', version: versions.json - implementation "com.squareup.retrofit2:retrofit:$versions.retrofit" - - implementation "com.afollestad:ason:$versions.publishVersion" -} - -publish { - userOrg = 'drummer-aidan' - groupId = 'com.afollestad' - artifactId = 'ason-retrofit' - publishVersion = versions.publishVersion - website = 'https://github.com/afollestad/ason' -} - -jacocoTestReport { - reports { - xml.enabled true - html.enabled false - } -} - -apply plugin: "com.diffplug.gradle.spotless" - -spotless { - java { - target "**/*.java" - trimTrailingWhitespace() - removeUnusedImports() - googleJavaFormat() - endWithNewline() - } -} diff --git a/asonretrofit/build/jacoco/test.exec b/asonretrofit/build/jacoco/test.exec deleted file mode 100644 index e0d81dc..0000000 Binary files a/asonretrofit/build/jacoco/test.exec and /dev/null differ diff --git a/asonretrofit/build/publications/maven/pom-default.xml b/asonretrofit/build/publications/maven/pom-default.xml deleted file mode 100644 index 6995a5d..0000000 --- a/asonretrofit/build/publications/maven/pom-default.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - 4.0.0 - com.afollestad - ason-retrofit - 1.4.16 - - - org.json - json - 20160810 - runtime - - - com.squareup.retrofit2 - retrofit - 2.3.0 - runtime - - - com.afollestad - ason - 1.4.16 - runtime - - - diff --git a/asonretrofit/build/reports/tests/test/classes/com.afollestad.asonretrofit.RequestTest.html b/asonretrofit/build/reports/tests/test/classes/com.afollestad.asonretrofit.RequestTest.html deleted file mode 100644 index 457ffe7..0000000 --- a/asonretrofit/build/reports/tests/test/classes/com.afollestad.asonretrofit.RequestTest.html +++ /dev/null @@ -1,106 +0,0 @@ - - - - - -Test results - Class com.afollestad.asonretrofit.RequestTest - - - - - -
-

Class com.afollestad.asonretrofit.RequestTest

- -
- - - - - -
-
- - - - - - - -
-
-
3
-

tests

-
-
-
-
0
-

failures

-
-
-
-
0
-

ignored

-
-
-
-
1.712s
-

duration

-
-
-
-
-
-
100%
-

successful

-
-
-
-
- -
-

Tests

- - - - - - - - - - - - - - - - - - - - - - - -
TestDurationResult
test_request_converter_array1.149spassed
test_request_converter_list0.285spassed
test_request_converter_object0.278spassed
-
-
- -
- - diff --git a/asonretrofit/build/reports/tests/test/classes/com.afollestad.asonretrofit.ResponseTest.html b/asonretrofit/build/reports/tests/test/classes/com.afollestad.asonretrofit.ResponseTest.html deleted file mode 100644 index 7f2bd3b..0000000 --- a/asonretrofit/build/reports/tests/test/classes/com.afollestad.asonretrofit.ResponseTest.html +++ /dev/null @@ -1,106 +0,0 @@ - - - - - -Test results - Class com.afollestad.asonretrofit.ResponseTest - - - - - -
-

Class com.afollestad.asonretrofit.ResponseTest

- -
- - - - - -
-
- - - - - - - -
-
-
3
-

tests

-
-
-
-
0
-

failures

-
-
-
-
0
-

ignored

-
-
-
-
1.123s
-

duration

-
-
-
-
-
-
100%
-

successful

-
-
-
-
- -
-

Tests

- - - - - - - - - - - - - - - - - - - - - - - -
TestDurationResult
test_response_converter_array0.731spassed
test_response_converter_list0.170spassed
test_response_converter_object0.222spassed
-
-
- -
- - diff --git a/asonretrofit/build/reports/tests/test/css/base-style.css b/asonretrofit/build/reports/tests/test/css/base-style.css deleted file mode 100644 index 4afa73e..0000000 --- a/asonretrofit/build/reports/tests/test/css/base-style.css +++ /dev/null @@ -1,179 +0,0 @@ - -body { - margin: 0; - padding: 0; - font-family: sans-serif; - font-size: 12pt; -} - -body, a, a:visited { - color: #303030; -} - -#content { - padding-left: 50px; - padding-right: 50px; - padding-top: 30px; - padding-bottom: 30px; -} - -#content h1 { - font-size: 160%; - margin-bottom: 10px; -} - -#footer { - margin-top: 100px; - font-size: 80%; - white-space: nowrap; -} - -#footer, #footer a { - color: #a0a0a0; -} - -#line-wrapping-toggle { - vertical-align: middle; -} - -#label-for-line-wrapping-toggle { - vertical-align: middle; -} - -ul { - margin-left: 0; -} - -h1, h2, h3 { - white-space: nowrap; -} - -h2 { - font-size: 120%; -} - -ul.tabLinks { - padding-left: 0; - padding-top: 10px; - padding-bottom: 10px; - overflow: auto; - min-width: 800px; - width: auto !important; - width: 800px; -} - -ul.tabLinks li { - float: left; - height: 100%; - list-style: none; - padding-left: 10px; - padding-right: 10px; - padding-top: 5px; - padding-bottom: 5px; - margin-bottom: 0; - -moz-border-radius: 7px; - border-radius: 7px; - margin-right: 25px; - border: solid 1px #d4d4d4; - background-color: #f0f0f0; -} - -ul.tabLinks li:hover { - background-color: #fafafa; -} - -ul.tabLinks li.selected { - background-color: #c5f0f5; - border-color: #c5f0f5; -} - -ul.tabLinks a { - font-size: 120%; - display: block; - outline: none; - text-decoration: none; - margin: 0; - padding: 0; -} - -ul.tabLinks li h2 { - margin: 0; - padding: 0; -} - -div.tab { -} - -div.selected { - display: block; -} - -div.deselected { - display: none; -} - -div.tab table { - min-width: 350px; - width: auto !important; - width: 350px; - border-collapse: collapse; -} - -div.tab th, div.tab table { - border-bottom: solid #d0d0d0 1px; -} - -div.tab th { - text-align: left; - white-space: nowrap; - padding-left: 6em; -} - -div.tab th:first-child { - padding-left: 0; -} - -div.tab td { - white-space: nowrap; - padding-left: 6em; - padding-top: 5px; - padding-bottom: 5px; -} - -div.tab td:first-child { - padding-left: 0; -} - -div.tab td.numeric, div.tab th.numeric { - text-align: right; -} - -span.code { - display: inline-block; - margin-top: 0em; - margin-bottom: 1em; -} - -span.code pre { - font-size: 11pt; - padding-top: 10px; - padding-bottom: 10px; - padding-left: 10px; - padding-right: 10px; - margin: 0; - background-color: #f7f7f7; - border: solid 1px #d0d0d0; - min-width: 700px; - width: auto !important; - width: 700px; -} - -span.wrapped pre { - word-wrap: break-word; - white-space: pre-wrap; - word-break: break-all; -} - -label.hidden { - display: none; -} \ No newline at end of file diff --git a/asonretrofit/build/reports/tests/test/css/style.css b/asonretrofit/build/reports/tests/test/css/style.css deleted file mode 100644 index 3dc4913..0000000 --- a/asonretrofit/build/reports/tests/test/css/style.css +++ /dev/null @@ -1,84 +0,0 @@ - -#summary { - margin-top: 30px; - margin-bottom: 40px; -} - -#summary table { - border-collapse: collapse; -} - -#summary td { - vertical-align: top; -} - -.breadcrumbs, .breadcrumbs a { - color: #606060; -} - -.infoBox { - width: 110px; - padding-top: 15px; - padding-bottom: 15px; - text-align: center; -} - -.infoBox p { - margin: 0; -} - -.counter, .percent { - font-size: 120%; - font-weight: bold; - margin-bottom: 8px; -} - -#duration { - width: 125px; -} - -#successRate, .summaryGroup { - border: solid 2px #d0d0d0; - -moz-border-radius: 10px; - border-radius: 10px; -} - -#successRate { - width: 140px; - margin-left: 35px; -} - -#successRate .percent { - font-size: 180%; -} - -.success, .success a { - color: #008000; -} - -div.success, #successRate.success { - background-color: #bbd9bb; - border-color: #008000; -} - -.failures, .failures a { - color: #b60808; -} - -.skipped, .skipped a { - color: #c09853; -} - -div.failures, #successRate.failures { - background-color: #ecdada; - border-color: #b60808; -} - -ul.linkList { - padding-left: 0; -} - -ul.linkList li { - list-style: none; - margin-bottom: 5px; -} diff --git a/asonretrofit/build/reports/tests/test/index.html b/asonretrofit/build/reports/tests/test/index.html deleted file mode 100644 index c3c9e8a..0000000 --- a/asonretrofit/build/reports/tests/test/index.html +++ /dev/null @@ -1,141 +0,0 @@ - - - - - -Test results - Test Summary - - - - - -
-

Test Summary

-
- - - - - -
-
- - - - - - - -
-
-
6
-

tests

-
-
-
-
0
-

failures

-
-
-
-
0
-

ignored

-
-
-
-
2.835s
-

duration

-
-
-
-
-
-
100%
-

successful

-
-
-
-
- -
-

Packages

- - - - - - - - - - - - - - - - - - - - - -
PackageTestsFailuresIgnoredDurationSuccess rate
-com.afollestad.asonretrofit -6002.835s100%
-
-
-

Classes

- - - - - - - - - - - - - - - - - - - - - - - - - - - -
ClassTestsFailuresIgnoredDurationSuccess rate
-com.afollestad.asonretrofit.RequestTest -3001.712s100%
-com.afollestad.asonretrofit.ResponseTest -3001.123s100%
-
-
- -
- - diff --git a/asonretrofit/build/reports/tests/test/js/report.js b/asonretrofit/build/reports/tests/test/js/report.js deleted file mode 100644 index 83bab4a..0000000 --- a/asonretrofit/build/reports/tests/test/js/report.js +++ /dev/null @@ -1,194 +0,0 @@ -(function (window, document) { - "use strict"; - - var tabs = {}; - - function changeElementClass(element, classValue) { - if (element.getAttribute("className")) { - element.setAttribute("className", classValue); - } else { - element.setAttribute("class", classValue); - } - } - - function getClassAttribute(element) { - if (element.getAttribute("className")) { - return element.getAttribute("className"); - } else { - return element.getAttribute("class"); - } - } - - function addClass(element, classValue) { - changeElementClass(element, getClassAttribute(element) + " " + classValue); - } - - function removeClass(element, classValue) { - changeElementClass(element, getClassAttribute(element).replace(classValue, "")); - } - - function initTabs() { - var container = document.getElementById("tabs"); - - tabs.tabs = findTabs(container); - tabs.titles = findTitles(tabs.tabs); - tabs.headers = findHeaders(container); - tabs.select = select; - tabs.deselectAll = deselectAll; - tabs.select(0); - - return true; - } - - function getCheckBox() { - return document.getElementById("line-wrapping-toggle"); - } - - function getLabelForCheckBox() { - return document.getElementById("label-for-line-wrapping-toggle"); - } - - function findCodeBlocks() { - var spans = document.getElementById("tabs").getElementsByTagName("span"); - var codeBlocks = []; - for (var i = 0; i < spans.length; ++i) { - if (spans[i].className.indexOf("code") >= 0) { - codeBlocks.push(spans[i]); - } - } - return codeBlocks; - } - - function forAllCodeBlocks(operation) { - var codeBlocks = findCodeBlocks(); - - for (var i = 0; i < codeBlocks.length; ++i) { - operation(codeBlocks[i], "wrapped"); - } - } - - function toggleLineWrapping() { - var checkBox = getCheckBox(); - - if (checkBox.checked) { - forAllCodeBlocks(addClass); - } else { - forAllCodeBlocks(removeClass); - } - } - - function initControls() { - if (findCodeBlocks().length > 0) { - var checkBox = getCheckBox(); - var label = getLabelForCheckBox(); - - checkBox.onclick = toggleLineWrapping; - checkBox.checked = false; - - removeClass(label, "hidden"); - } - } - - function switchTab() { - var id = this.id.substr(1); - - for (var i = 0; i < tabs.tabs.length; i++) { - if (tabs.tabs[i].id === id) { - tabs.select(i); - break; - } - } - - return false; - } - - function select(i) { - this.deselectAll(); - - changeElementClass(this.tabs[i], "tab selected"); - changeElementClass(this.headers[i], "selected"); - - while (this.headers[i].firstChild) { - this.headers[i].removeChild(this.headers[i].firstChild); - } - - var h2 = document.createElement("H2"); - - h2.appendChild(document.createTextNode(this.titles[i])); - this.headers[i].appendChild(h2); - } - - function deselectAll() { - for (var i = 0; i < this.tabs.length; i++) { - changeElementClass(this.tabs[i], "tab deselected"); - changeElementClass(this.headers[i], "deselected"); - - while (this.headers[i].firstChild) { - this.headers[i].removeChild(this.headers[i].firstChild); - } - - var a = document.createElement("A"); - - a.setAttribute("id", "ltab" + i); - a.setAttribute("href", "#tab" + i); - a.onclick = switchTab; - a.appendChild(document.createTextNode(this.titles[i])); - - this.headers[i].appendChild(a); - } - } - - function findTabs(container) { - return findChildElements(container, "DIV", "tab"); - } - - function findHeaders(container) { - var owner = findChildElements(container, "UL", "tabLinks"); - return findChildElements(owner[0], "LI", null); - } - - function findTitles(tabs) { - var titles = []; - - for (var i = 0; i < tabs.length; i++) { - var tab = tabs[i]; - var header = findChildElements(tab, "H2", null)[0]; - - header.parentNode.removeChild(header); - - if (header.innerText) { - titles.push(header.innerText); - } else { - titles.push(header.textContent); - } - } - - return titles; - } - - function findChildElements(container, name, targetClass) { - var elements = []; - var children = container.childNodes; - - for (var i = 0; i < children.length; i++) { - var child = children.item(i); - - if (child.nodeType === 1 && child.nodeName === name) { - if (targetClass && child.className.indexOf(targetClass) < 0) { - continue; - } - - elements.push(child); - } - } - - return elements; - } - - // Entry point. - - window.onload = function() { - initTabs(); - initControls(); - }; -} (window, window.document)); \ No newline at end of file diff --git a/asonretrofit/build/reports/tests/test/packages/com.afollestad.asonretrofit.html b/asonretrofit/build/reports/tests/test/packages/com.afollestad.asonretrofit.html deleted file mode 100644 index 2223896..0000000 --- a/asonretrofit/build/reports/tests/test/packages/com.afollestad.asonretrofit.html +++ /dev/null @@ -1,113 +0,0 @@ - - - - - -Test results - Package com.afollestad.asonretrofit - - - - - -
-

Package com.afollestad.asonretrofit

- -
- - - - - -
-
- - - - - - - -
-
-
6
-

tests

-
-
-
-
0
-

failures

-
-
-
-
0
-

ignored

-
-
-
-
2.835s
-

duration

-
-
-
-
-
-
100%
-

successful

-
-
-
-
- -
-

Classes

- - - - - - - - - - - - - - - - - - - - - - - - - - - -
ClassTestsFailuresIgnoredDurationSuccess rate
-RequestTest -3001.712s100%
-ResponseTest -3001.123s100%
-
-
- -
- - diff --git a/asonretrofit/build/test-results/test/TEST-com.afollestad.asonretrofit.RequestTest.xml b/asonretrofit/build/test-results/test/TEST-com.afollestad.asonretrofit.RequestTest.xml deleted file mode 100644 index 03e6558..0000000 --- a/asonretrofit/build/test-results/test/TEST-com.afollestad.asonretrofit.RequestTest.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/asonretrofit/build/test-results/test/TEST-com.afollestad.asonretrofit.ResponseTest.xml b/asonretrofit/build/test-results/test/TEST-com.afollestad.asonretrofit.ResponseTest.xml deleted file mode 100644 index 560fec7..0000000 --- a/asonretrofit/build/test-results/test/TEST-com.afollestad.asonretrofit.ResponseTest.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/asonretrofit/build/test-results/test/binary/output.bin b/asonretrofit/build/test-results/test/binary/output.bin deleted file mode 100644 index e69de29..0000000 diff --git a/asonretrofit/build/test-results/test/binary/output.bin.idx b/asonretrofit/build/test-results/test/binary/output.bin.idx deleted file mode 100644 index f76dd23..0000000 Binary files a/asonretrofit/build/test-results/test/binary/output.bin.idx and /dev/null differ diff --git a/asonretrofit/build/test-results/test/binary/results.bin b/asonretrofit/build/test-results/test/binary/results.bin deleted file mode 100644 index 4852b22..0000000 Binary files a/asonretrofit/build/test-results/test/binary/results.bin and /dev/null differ diff --git a/asonretrofit/build/tmp/expandedArchives/org.jacoco.agent-0.7.8.jar_9dij2jmj8gj16cihm5tukv6pf/META-INF/MANIFEST.MF b/asonretrofit/build/tmp/expandedArchives/org.jacoco.agent-0.7.8.jar_9dij2jmj8gj16cihm5tukv6pf/META-INF/MANIFEST.MF deleted file mode 100644 index 43b9d9f..0000000 --- a/asonretrofit/build/tmp/expandedArchives/org.jacoco.agent-0.7.8.jar_9dij2jmj8gj16cihm5tukv6pf/META-INF/MANIFEST.MF +++ /dev/null @@ -1,16 +0,0 @@ -Manifest-Version: 1.0 -Archiver-Version: Plexus Archiver -Created-By: Apache Maven -Built-By: godin -Build-Jdk: 1.8.0_112 -Eclipse-SourceReferences: scm:git:git://github.com/jacoco/jacoco.git;p - ath="org.jacoco.agent";commitId=6e9b6f2ce94aec927c5ce8103545f28f4e587 - 5b2 -Bundle-ManifestVersion: 2 -Bundle-Name: JaCoCo Agent -Bundle-SymbolicName: org.jacoco.agent -Bundle-Version: 0.7.8.201612092310 -Bundle-Vendor: Mountainminds GmbH & Co. KG -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Export-Package: org.jacoco.agent;version="0.7.8" - diff --git a/asonretrofit/build/tmp/expandedArchives/org.jacoco.agent-0.7.8.jar_9dij2jmj8gj16cihm5tukv6pf/META-INF/maven/org.jacoco/org.jacoco.agent/pom.properties b/asonretrofit/build/tmp/expandedArchives/org.jacoco.agent-0.7.8.jar_9dij2jmj8gj16cihm5tukv6pf/META-INF/maven/org.jacoco/org.jacoco.agent/pom.properties deleted file mode 100644 index fc86fa7..0000000 --- a/asonretrofit/build/tmp/expandedArchives/org.jacoco.agent-0.7.8.jar_9dij2jmj8gj16cihm5tukv6pf/META-INF/maven/org.jacoco/org.jacoco.agent/pom.properties +++ /dev/null @@ -1,5 +0,0 @@ -#Generated by Maven -#Sat Dec 10 00:20:28 CET 2016 -version=0.7.8 -groupId=org.jacoco -artifactId=org.jacoco.agent diff --git a/asonretrofit/build/tmp/expandedArchives/org.jacoco.agent-0.7.8.jar_9dij2jmj8gj16cihm5tukv6pf/META-INF/maven/org.jacoco/org.jacoco.agent/pom.xml b/asonretrofit/build/tmp/expandedArchives/org.jacoco.agent-0.7.8.jar_9dij2jmj8gj16cihm5tukv6pf/META-INF/maven/org.jacoco/org.jacoco.agent/pom.xml deleted file mode 100644 index dfe9f6d..0000000 --- a/asonretrofit/build/tmp/expandedArchives/org.jacoco.agent-0.7.8.jar_9dij2jmj8gj16cihm5tukv6pf/META-INF/maven/org.jacoco/org.jacoco.agent/pom.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - - 4.0.0 - - - org.jacoco - org.jacoco.build - 0.7.8 - ../org.jacoco.build - - - org.jacoco.agent - - JaCoCo :: Agent - JaCoCo Agent - - - src - - - - org.apache.maven.plugins - maven-dependency-plugin - - - prepare-package - - copy - - - - - ${project.groupId} - org.jacoco.agent.rt - all - ${project.version} - jacocoagent.jar - - - ${project.build.directory}/classes - false - false - true - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-artifacts - package - - attach-artifact - - - - - ${project.build.directory}/classes/jacocoagent.jar - jar - runtime - - - - - - - - - diff --git a/asonretrofit/build/tmp/expandedArchives/org.jacoco.agent-0.7.8.jar_9dij2jmj8gj16cihm5tukv6pf/about.html b/asonretrofit/build/tmp/expandedArchives/org.jacoco.agent-0.7.8.jar_9dij2jmj8gj16cihm5tukv6pf/about.html deleted file mode 100644 index b235da7..0000000 --- a/asonretrofit/build/tmp/expandedArchives/org.jacoco.agent-0.7.8.jar_9dij2jmj8gj16cihm5tukv6pf/about.html +++ /dev/null @@ -1,73 +0,0 @@ - - - - -About - - - -

About This Content

- -

- 2016/12/09 -

- -

License

- -

- All Content in this plug-in is made available by Mountainminds GmbH & Co. - KG, Munich. Unless otherwise indicated below, the Content is provided to you - under the terms and conditions of the Eclipse Public License Version 1.0 - ("EPL"). A copy of the EPL is available at - http://www.eclipse.org/legal/epl-v10.html. - For purposes of the EPL, "Program" will mean the Content. -

- -

Third Party Content

- -

- The Content includes items that have been sourced from third parties as set - out below. -

- -

ASM

- -

- This plug-in contains the ASM library - which is subject to the terms and conditions of the following license: -

- -
-Copyright (c) 2012 France Télécom
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-
-3. Neither the name of the copyright holders nor the names of its
-   contributors may be used to endorse or promote products derived from
-   this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
-THE POSSIBILITY OF SUCH DAMAGE.
-
- - - \ No newline at end of file diff --git a/asonretrofit/build/tmp/jar/MANIFEST.MF b/asonretrofit/build/tmp/jar/MANIFEST.MF deleted file mode 100644 index 58630c0..0000000 --- a/asonretrofit/build/tmp/jar/MANIFEST.MF +++ /dev/null @@ -1,2 +0,0 @@ -Manifest-Version: 1.0 - diff --git a/asonretrofit/build/tmp/mavenJavadocJar/MANIFEST.MF b/asonretrofit/build/tmp/mavenJavadocJar/MANIFEST.MF deleted file mode 100644 index 58630c0..0000000 --- a/asonretrofit/build/tmp/mavenJavadocJar/MANIFEST.MF +++ /dev/null @@ -1,2 +0,0 @@ -Manifest-Version: 1.0 - diff --git a/asonretrofit/build/tmp/mavenSourcesJar/MANIFEST.MF b/asonretrofit/build/tmp/mavenSourcesJar/MANIFEST.MF deleted file mode 100644 index 58630c0..0000000 --- a/asonretrofit/build/tmp/mavenSourcesJar/MANIFEST.MF +++ /dev/null @@ -1,2 +0,0 @@ -Manifest-Version: 1.0 - diff --git a/asonretrofit/gradle/wrapper/gradle-wrapper.jar b/asonretrofit/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 990e351..0000000 Binary files a/asonretrofit/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/asonretrofit/gradle/wrapper/gradle-wrapper.properties b/asonretrofit/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 8ca176b..0000000 --- a/asonretrofit/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Sun Aug 27 16:53:00 CDT 2017 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip diff --git a/asonretrofit/gradlew b/asonretrofit/gradlew deleted file mode 100755 index 4453cce..0000000 --- a/asonretrofit/gradlew +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env sh - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save ( ) { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - -exec "$JAVACMD" "$@" diff --git a/asonretrofit/gradlew.bat b/asonretrofit/gradlew.bat deleted file mode 100644 index e95643d..0000000 --- a/asonretrofit/gradlew.bat +++ /dev/null @@ -1,84 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/asonretrofit/settings.gradle b/asonretrofit/settings.gradle deleted file mode 100644 index 6cf18cd..0000000 --- a/asonretrofit/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'asonretrofit' - diff --git a/asonretrofit/src/main/java/com/afollestad/asonretrofit/AsonConverterFactory.java b/asonretrofit/src/main/java/com/afollestad/asonretrofit/AsonConverterFactory.java deleted file mode 100644 index 3dadf1b..0000000 --- a/asonretrofit/src/main/java/com/afollestad/asonretrofit/AsonConverterFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.afollestad.asonretrofit; - -import com.afollestad.asonretrofit.AsonResponseBodyConverter.Mode; -import java.lang.annotation.Annotation; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.List; -import okhttp3.RequestBody; -import okhttp3.ResponseBody; -import retrofit2.Converter; -import retrofit2.Retrofit; - -public final class AsonConverterFactory extends Converter.Factory { - - @Override - public Converter responseBodyConverter( - Type type, Annotation[] annotations, Retrofit retrofit) { - if (type instanceof ParameterizedType) { - ParameterizedType paramType = (ParameterizedType) type; - if (List.class == paramType.getRawType()) { - return new AsonResponseBodyConverter<>( - Mode.List, (Class) paramType.getActualTypeArguments()[0]); - } - } else if (type instanceof Class) { - Class cls = (Class) type; - if (cls.isArray()) { - return new AsonResponseBodyConverter<>(Mode.Array, cls); - } else { - return new AsonResponseBodyConverter<>(Mode.Object, cls); - } - } - return null; - } - - @Override - public Converter requestBodyConverter( - Type type, - Annotation[] parameterAnnotations, - Annotation[] methodAnnotations, - Retrofit retrofit) { - return new AsonRequestBodyConverter<>(); - } -} diff --git a/asonretrofit/src/main/java/com/afollestad/asonretrofit/AsonRequestBodyConverter.java b/asonretrofit/src/main/java/com/afollestad/asonretrofit/AsonRequestBodyConverter.java deleted file mode 100644 index 0b2afe5..0000000 --- a/asonretrofit/src/main/java/com/afollestad/asonretrofit/AsonRequestBodyConverter.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.afollestad.asonretrofit; - -import com.afollestad.ason.Ason; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.nio.charset.Charset; -import java.util.List; -import okhttp3.MediaType; -import okhttp3.RequestBody; -import okio.Buffer; -import retrofit2.Converter; - -/** @author Aidan Follestad (afollestad) */ -public class AsonRequestBodyConverter implements Converter { - - private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8"); - private static final Charset UTF_8 = Charset.forName("UTF-8"); - - @Override - public RequestBody convert(T value) throws IOException { - String body; - if (value instanceof List) { - body = Ason.serializeList((List) value).toString(); - } else if (value.getClass().isArray()) { - body = Ason.serializeArray(value).toString(); - } else { - body = Ason.serialize(value).toString(); - } - if (body == null) { - return null; - } - Buffer buffer = new Buffer(); - Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8); - writer.write(body); - writer.close(); - return RequestBody.create(MEDIA_TYPE, buffer.readByteString()); - } -} diff --git a/asonretrofit/src/main/java/com/afollestad/asonretrofit/AsonResponseBodyConverter.java b/asonretrofit/src/main/java/com/afollestad/asonretrofit/AsonResponseBodyConverter.java deleted file mode 100644 index 56e3367..0000000 --- a/asonretrofit/src/main/java/com/afollestad/asonretrofit/AsonResponseBodyConverter.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.afollestad.asonretrofit; - -import com.afollestad.ason.Ason; -import com.afollestad.ason.AsonArray; -import java.io.IOException; -import okhttp3.ResponseBody; -import retrofit2.Converter; - -/** @author Aidan Follestad (afollestad) */ -class AsonResponseBodyConverter implements Converter { - - public enum Mode { - Object, - Array, - List - } - - private final Mode mode; - private final Class targetType; - - AsonResponseBodyConverter(Mode mode, Class targetType) { - this.mode = mode; - this.targetType = targetType; - } - - @SuppressWarnings("unchecked") - @Override - public T convert(ResponseBody value) throws IOException { - String body = value.string(); - switch (mode) { - case Array: - return (T) new AsonArray(body).deserialize(targetType); - case List: - return (T) new AsonArray(body).deserializeList(targetType); - default: - return (T) new Ason(body).deserialize(targetType); - } - } -} diff --git a/asonretrofit/src/test/java/com/afollestad/asonretrofit/EchoArrayWrapper.java b/asonretrofit/src/test/java/com/afollestad/asonretrofit/EchoArrayWrapper.java deleted file mode 100644 index bf4b53f..0000000 --- a/asonretrofit/src/test/java/com/afollestad/asonretrofit/EchoArrayWrapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.afollestad.asonretrofit; - -/** - * Postman Echo returns the sent request in an object called "data". - * - * @author Aidan Follestad (afollestad) - */ -public class EchoArrayWrapper { - - TestPerson[] data; -} diff --git a/asonretrofit/src/test/java/com/afollestad/asonretrofit/EchoListWrapper.java b/asonretrofit/src/test/java/com/afollestad/asonretrofit/EchoListWrapper.java deleted file mode 100644 index 2db6786..0000000 --- a/asonretrofit/src/test/java/com/afollestad/asonretrofit/EchoListWrapper.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.afollestad.asonretrofit; - -import java.util.List; - -/** - * Postman Echo returns the sent request in an object called "data". - * - * @author Aidan Follestad (afollestad) - */ -public class EchoListWrapper { - - List data; -} diff --git a/asonretrofit/src/test/java/com/afollestad/asonretrofit/EchoObjectWrapper.java b/asonretrofit/src/test/java/com/afollestad/asonretrofit/EchoObjectWrapper.java deleted file mode 100644 index 9f58643..0000000 --- a/asonretrofit/src/test/java/com/afollestad/asonretrofit/EchoObjectWrapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.afollestad.asonretrofit; - -/** - * Postman Echo returns the sent request in an object called "data". - * - * @author Aidan Follestad (afollestad) - */ -public class EchoObjectWrapper { - - TestData data; -} diff --git a/asonretrofit/src/test/java/com/afollestad/asonretrofit/RequestTest.java b/asonretrofit/src/test/java/com/afollestad/asonretrofit/RequestTest.java deleted file mode 100644 index c3c20b1..0000000 --- a/asonretrofit/src/test/java/com/afollestad/asonretrofit/RequestTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.afollestad.asonretrofit; - -import static com.google.common.truth.Truth.assertThat; - -import java.util.ArrayList; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import retrofit2.Retrofit; -import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; - -public class RequestTest { - - private TestService service; - - @Before - public void setup() { - Retrofit retrofit = - new Retrofit.Builder() - .baseUrl("https://postman-echo.com") - .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) - .addConverterFactory(new AsonConverterFactory()) - .build(); - service = retrofit.create(TestService.class); - } - - @Test - public void test_request_converter_object() { - TestData request = new TestData(); - request.count = 2; - request.people = - new TestPerson[] {new TestPerson(1, "Aidan", 22), new TestPerson(2, "Nina", 22)}; - - EchoObjectWrapper responseWrapper = service.putTestObject(request).blockingGet().body(); - assertThat(responseWrapper).isNotNull(); - TestData response = responseWrapper.data; - assertThat(response).isNotNull(); - assertThat(response.count).isEqualTo(2); - assertThat(response.people).isNotNull(); - assertThat(response.people.length).isEqualTo(response.count); - assertThat(response.people[0].id).isEqualTo(1); - assertThat(response.people[0].name).isEqualTo("Aidan"); - assertThat(response.people[0].age).isEqualTo(22); - assertThat(response.people[1].id).isEqualTo(2); - assertThat(response.people[1].name).isEqualTo("Nina"); - assertThat(response.people[1].age).isEqualTo(22); - } - - @Test - public void test_request_converter_array() { - TestPerson[] request = - new TestPerson[] {new TestPerson(1, "Aidan", 22), new TestPerson(2, "Nina", 22)}; - EchoArrayWrapper responseWrapper = service.putTestArray(request).blockingGet().body(); - assertThat(responseWrapper).isNotNull(); - - TestPerson[] response = responseWrapper.data; - assertThat(response).isNotNull(); - assertThat(response.length).isEqualTo(2); - assertThat(response[0].id).isEqualTo(1); - assertThat(response[0].name).isEqualTo("Aidan"); - assertThat(response[0].age).isEqualTo(22); - assertThat(response[1].id).isEqualTo(2); - assertThat(response[1].name).isEqualTo("Nina"); - assertThat(response[1].age).isEqualTo(22); - } - - @Test - public void test_request_converter_list() { - List request = new ArrayList<>(2); - request.add(new TestPerson(1, "Aidan", 22)); - request.add(new TestPerson(2, "Nina", 22)); - EchoListWrapper responseWrapper = service.putTestList(request).blockingGet().body(); - assertThat(responseWrapper).isNotNull(); - - List response = responseWrapper.data; - assertThat(response).isNotNull(); - assertThat(response.size()).isEqualTo(2); - assertThat(response.get(0).id).isEqualTo(1); - assertThat(response.get(0).name).isEqualTo("Aidan"); - assertThat(response.get(0).age).isEqualTo(22); - assertThat(response.get(1).id).isEqualTo(2); - assertThat(response.get(1).name).isEqualTo("Nina"); - assertThat(response.get(1).age).isEqualTo(22); - } -} diff --git a/asonretrofit/src/test/java/com/afollestad/asonretrofit/ResponseTest.java b/asonretrofit/src/test/java/com/afollestad/asonretrofit/ResponseTest.java deleted file mode 100644 index ad578c9..0000000 --- a/asonretrofit/src/test/java/com/afollestad/asonretrofit/ResponseTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.afollestad.asonretrofit; - -import static com.google.common.truth.Truth.assertThat; - -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import retrofit2.Retrofit; -import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; - -public class ResponseTest { - - private TestService service; - - @Before - public void setup() { - Retrofit retrofit = - new Retrofit.Builder() - .baseUrl("https://raw.githubusercontent.com") - .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) - .addConverterFactory(new AsonConverterFactory()) - .build(); - service = retrofit.create(TestService.class); - } - - @Test - public void test_response_converter_object() { - TestData response = service.getTestObject().blockingGet().body(); - assertThat(response).isNotNull(); - assertThat(response.count).isEqualTo(2); - assertThat(response.people).isNotNull(); - assertThat(response.people.length).isEqualTo(response.count); - assertThat(response.people[0].id).isEqualTo(1); - assertThat(response.people[0].name).isEqualTo("Aidan"); - assertThat(response.people[0].age).isEqualTo(22); - assertThat(response.people[1].id).isEqualTo(2); - assertThat(response.people[1].name).isEqualTo("Nina"); - assertThat(response.people[1].age).isEqualTo(22); - } - - @Test - public void test_response_converter_array() { - TestPerson[] response = service.getTestArray().blockingGet().body(); - assertThat(response).isNotNull(); - assertThat(response.length).isEqualTo(2); - assertThat(response[0].id).isEqualTo(1); - assertThat(response[0].name).isEqualTo("Aidan"); - assertThat(response[0].age).isEqualTo(22); - assertThat(response[1].id).isEqualTo(2); - assertThat(response[1].name).isEqualTo("Nina"); - assertThat(response[1].age).isEqualTo(22); - } - - @Test - public void test_response_converter_list() { - List response = service.getTestList().blockingGet().body(); - assertThat(response).isNotNull(); - assertThat(response.size()).isEqualTo(2); - assertThat(response.get(0).id).isEqualTo(1); - assertThat(response.get(0).name).isEqualTo("Aidan"); - assertThat(response.get(0).age).isEqualTo(22); - assertThat(response.get(1).id).isEqualTo(2); - assertThat(response.get(1).name).isEqualTo("Nina"); - assertThat(response.get(1).age).isEqualTo(22); - } -} diff --git a/asonretrofit/src/test/java/com/afollestad/asonretrofit/TestData.java b/asonretrofit/src/test/java/com/afollestad/asonretrofit/TestData.java deleted file mode 100644 index d9c326e..0000000 --- a/asonretrofit/src/test/java/com/afollestad/asonretrofit/TestData.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.afollestad.asonretrofit; - -public class TestData { - - public int count; - public TestPerson[] people; -} diff --git a/asonretrofit/src/test/java/com/afollestad/asonretrofit/TestPerson.java b/asonretrofit/src/test/java/com/afollestad/asonretrofit/TestPerson.java deleted file mode 100644 index b6478af..0000000 --- a/asonretrofit/src/test/java/com/afollestad/asonretrofit/TestPerson.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.afollestad.asonretrofit; - -import com.afollestad.ason.AsonName; - -public class TestPerson { - - TestPerson() {} - - public TestPerson(int id, String name, int age) { - this.id = id; - this.name = name; - this.age = age; - } - - @AsonName(name = "_id") - public int id; - - public String name; - public int age; -} diff --git a/asonretrofit/src/test/java/com/afollestad/asonretrofit/TestService.java b/asonretrofit/src/test/java/com/afollestad/asonretrofit/TestService.java deleted file mode 100644 index 3e07514..0000000 --- a/asonretrofit/src/test/java/com/afollestad/asonretrofit/TestService.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.afollestad.asonretrofit; - -import io.reactivex.Single; -import java.util.List; -import retrofit2.Response; -import retrofit2.http.Body; -import retrofit2.http.GET; -import retrofit2.http.PUT; - -public interface TestService { - - @GET("/afollestad/ason/master/asonretrofit/test.json") - Single> getTestObject(); - - @GET("/afollestad/ason/master/asonretrofit/test2.json") - Single>> getTestList(); - - @GET("/afollestad/ason/master/asonretrofit/test2.json") - Single> getTestArray(); - - @PUT("/put") - Single> putTestObject(@Body TestData object); - - @PUT("/put") - Single> putTestArray(@Body TestPerson[] array); - - @PUT("/put") - Single> putTestList(@Body List list); -} diff --git a/asonretrofit/test.json b/asonretrofit/test.json deleted file mode 100644 index 227c13b..0000000 --- a/asonretrofit/test.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "count": 2, - "people": [ - { - "_id": 1, - "name": "Aidan", - "age": 22 - }, - { - "_id": 2, - "name": "Nina", - "age": 22 - } - ] -} \ No newline at end of file diff --git a/asonretrofit/test2.json b/asonretrofit/test2.json deleted file mode 100644 index d5a6d7b..0000000 --- a/asonretrofit/test2.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "_id": 1, - "name": "Aidan", - "age": 22 - }, - { - "_id": 2, - "name": "Nina", - "age": 22 - } -] \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4167236..35b00e2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,45 +1,40 @@ -apply from: "$rootDir/gradle/dependencies.gradle" - group 'com.afollestad' -version versions.publishVersion +version '1.4.13' apply plugin: 'java' apply plugin: 'idea' apply plugin: 'jacoco' apply plugin: 'com.novoda.bintray-release' -sourceCompatibility = 1.7 +targetCompatibility = '1.7' +sourceCompatibility = '1.7' buildscript { - apply from: "$rootDir/gradle/dependencies.gradle" - repositories { jcenter() } dependencies { - classpath "com.novoda:bintray-release:$versions.bintrayRelease" - classpath "com.diffplug.spotless:spotless-plugin-gradle:$versions.spotlessPlugin" + classpath 'com.novoda:bintray-release:+' } } repositories { mavenCentral() - jcenter() } dependencies { - testCompile group: 'junit', name: 'junit', version: versions.junit - testCompile group: 'com.google.code.gson', name: 'gson', version: versions.gson + testCompile group: 'junit', name: 'junit', version: '4.11' + testCompile group: 'com.google.code.gson', name: 'gson', version: '2.8.0' - implementation group: 'org.json', name: 'json', version: versions.json - implementation group: 'com.intellij', name: 'annotations', version: versions.intellij + compile group: 'org.json', name: 'json', version: '20160810' + compile group: 'com.intellij', name: 'annotations', version: '12.0' } publish { userOrg = 'drummer-aidan' groupId = 'com.afollestad' artifactId = 'ason' - publishVersion = versions.publishVersion + publishVersion = '1.4.13' website = 'https://github.com/afollestad/ason' } @@ -48,16 +43,4 @@ jacocoTestReport { xml.enabled true html.enabled false } -} - -apply plugin: "com.diffplug.gradle.spotless" - -spotless { - java { - target "**/*.java" - trimTrailingWhitespace() - removeUnusedImports() - googleJavaFormat() - endWithNewline() - } -} +} \ No newline at end of file diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle deleted file mode 100644 index b39aebd..0000000 --- a/gradle/dependencies.gradle +++ /dev/null @@ -1,14 +0,0 @@ -ext.versions = [ - publishVersion: '1.4.16', - - junit : '4.11', - json : '20160810', - intellij : '12.0', - gson : '2.8.0', - retrofit : '2.3.0', - rxJava2 : '2.+', - truth : '0.34', - - spotlessPlugin: '3.5.1', - bintrayRelease: '+' -] \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ed88a04..6ffa237 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 74bb778..b8a54e8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Fri Feb 03 14:57:11 CST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-bin.zip diff --git a/gradlew b/gradlew index cccdd3d..9aa616c 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash ############################################################################## ## @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS="" # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn () { +warn ( ) { echo "$*" } -die () { +die ( ) { echo echo "$*" echo @@ -154,19 +154,16 @@ if $cygwin ; then esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") } -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then +if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then cd "$(dirname "$0")" fi -exec "$JAVACMD" "$@" +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat index e95643d..f955316 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,84 +1,84 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/com/afollestad/ason/Ason.java b/src/main/java/com/afollestad/ason/Ason.java index c08cdc2..219114a 100644 --- a/src/main/java/com/afollestad/ason/Ason.java +++ b/src/main/java/com/afollestad/ason/Ason.java @@ -58,83 +58,49 @@ public Ason(@Nullable String json) { } public static Ason serialize(@Nullable Object object) { - return serialize(object, false); - } - - public static Ason serialize(@Nullable Object object, boolean recursive) { - return AsonSerializer.get().serialize(object, recursive); + return AsonSerializer.get().serialize(object); } public static AsonArray serializeArray(@Nullable Object object) { - return serializeArray(object, false); - } - - public static AsonArray serializeArray(@Nullable Object object, boolean recursive) { - return AsonSerializer.get().serializeArray(object, recursive); + return AsonSerializer.get().serializeArray(object); } public static AsonArray serializeList(@Nullable List object) { - return serializeList(object, false); - } - - public static AsonArray serializeList(@Nullable List object, boolean recursive) { - return AsonSerializer.get().serializeList(object, recursive); + return AsonSerializer.get().serializeList(object); } public static T deserialize(@Nullable String json, @NotNull Class cls) { - return deserialize(json, cls, false); - } - - public static T deserialize(@Nullable String json, @NotNull Class cls, boolean recursive) { if (isJsonArray(json)) { AsonArray ason = new AsonArray(json); - return AsonSerializer.get().deserializeArray(ason, cls, recursive); + return AsonSerializer.get().deserializeArray(ason, cls); } else { Ason ason = new Ason(json); - return AsonSerializer.get().deserialize(ason, cls, recursive); + return AsonSerializer.get().deserialize(ason, cls); } } public static T deserialize(@Nullable Ason json, @NonNls Class cls) { - return deserialize(json, cls, false); - } - - public static T deserialize(@Nullable Ason json, @NonNls Class cls, boolean recursive) { - return AsonSerializer.get().deserialize(json, cls, recursive); + return AsonSerializer.get().deserialize(json, cls); } public static T deserialize(@Nullable AsonArray json, @NonNls Class cls) { - return deserialize(json, cls, false); - } - - public static T deserialize( - @Nullable AsonArray json, @NonNls Class cls, boolean recursive) { - return AsonSerializer.get().deserializeArray(json, cls, recursive); + return AsonSerializer.get().deserializeArray(json, cls); } public static List deserializeList(@Nullable String json, @NotNull Class cls) { - return deserializeList(json, cls, false); - } - - public static List deserializeList( - @Nullable String json, @NotNull Class cls, boolean recursive) { AsonArray array = new AsonArray(json); - return AsonSerializer.get().deserializeList(array, cls, recursive); + return AsonSerializer.get().deserializeList(array, cls); } public static List deserializeList(@Nullable AsonArray json, @NotNull Class cls) { - return deserializeList(json, cls, false); + return AsonSerializer.get().deserializeList(json, cls); } - public static List deserializeList( - @Nullable AsonArray json, @NotNull Class cls, boolean recursive) { - return AsonSerializer.get().deserializeList(json, cls, recursive); - } - - private void putInternal(JSONArray intoArray, JSONObject intoObject, String key, Object value) { + private Ason putInternal(JSONArray intoArray, JSONObject intoObject, String key, Object value) { invalidateLoadedFields(); if (value == null || JSONObject.NULL.equals(value) || JSONObject.NULL == value) { json.put(key, JSONObject.NULL); + return this; } else if (isPrimitive(value) || value instanceof JSONObject || value instanceof JSONArray) { if (value instanceof Byte) { value = ((Byte) value).intValue(); @@ -157,6 +123,7 @@ private void putInternal(JSONArray intoArray, JSONObject intoObject, String key, } else { putInternal(intoArray, intoObject, key, serializer.serialize(value)); } + return this; } public Ason putNull(@NotNull String key) { @@ -350,7 +317,7 @@ public T get(@NotNull String key, @NotNull Class cls, @Nullable T default } else if (cls.isArray()) { if (!(value instanceof AsonArray)) { throw new IllegalStateException( - "Expected a com.afollestad.ason.AsonArray to convert to " + "Expected a AsonArray to convert to " + cls.getName() + ", found " + value.getClass().getName() @@ -365,7 +332,7 @@ public T get(@NotNull String key, @NotNull Class cls, @Nullable T default } else { if (!(value instanceof Ason)) { throw new IllegalStateException( - "Expected a com.afollestad.ason.Ason to convert to " + "Expected a Ason to convert to " + cls.getName() + ", found " + value.getClass().getName() @@ -384,7 +351,7 @@ public List getList(@NotNull String key, Class itemCls) { } if (!(value instanceof AsonArray)) { throw new IllegalStateException( - "Expected a com.afollestad.ason.AsonArray to convert to List, " + "Expected a AsonArray to convert to List, " + "found " + value.getClass().getName() + "."); @@ -475,8 +442,4 @@ public String toString(int indentSpaces) { public T deserialize(@NonNls Class cls) { return deserialize(this, cls); } - - public T deserialize(@NonNls Class cls, boolean recursive) { - return deserialize(this, cls, recursive); - } } diff --git a/src/main/java/com/afollestad/ason/AsonArray.java b/src/main/java/com/afollestad/ason/AsonArray.java index 2799849..eaca915 100644 --- a/src/main/java/com/afollestad/ason/AsonArray.java +++ b/src/main/java/com/afollestad/ason/AsonArray.java @@ -15,7 +15,9 @@ import org.json.JSONException; import org.json.JSONObject; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ @SuppressWarnings({"unchecked", "WeakerAccess", "unused", "SameParameterValue"}) public class AsonArray implements Iterable { @@ -132,7 +134,7 @@ public Ason getJsonObject(int index) { throw new IndexOutOfBoundsException("Index " + index + " is out of bounds for this array!"); } JSONObject object = array.optJSONObject(index); - if (isNull(object)) { + if (Util.isNull(object)) { return null; } return new Ason(object); @@ -144,7 +146,7 @@ public AsonArray getJsonArray(int index) { throw new IndexOutOfBoundsException("Index " + index + " is out of bounds for this array!"); } JSONArray ary = array.optJSONArray(index); - if (isNull(ary)) { + if (Util.isNull(ary)) { return null; } return new AsonArray<>(ary); @@ -156,18 +158,18 @@ Object getInternal(int index, @Nullable String path) { } Object value = array.opt(index); if (path != null) { - if (isNull(value)) { + if (Util.isNull(value)) { return null; } if (!(value instanceof JSONObject) && !(value instanceof Ason)) { throw new IllegalStateException( - "Cannot get from an com.afollestad.ason.AsonArray using a " + "Cannot get from an AsonArray using a " + "path when array items are not objects (they're probably primitives)."); } value = getPathValue((JSONObject) value, path, splitPath(path)); } - if (isNull(value)) { + if (Util.isNull(value)) { return null; } @@ -205,7 +207,7 @@ public T get(int index, @Nullable String path) { public T get(int index, @Nullable String path, Class cls) { if (isList(cls)) { throw new IllegalStateException( - "Use com.afollestad.ason.AsonArray.getList(...) to retrieve List<> children instead of get(...)."); + "Use AsonArray.getList(...) to retrieve List<> children instead of get(...)."); } Object value = getInternal(index, path); @@ -241,8 +243,8 @@ public AsonArray remove(int index) { public boolean equal(int index, @Nullable T value) { T actual = get(index); - if (isNull(actual)) { - return isNull(value); + if (Util.isNull(actual)) { + return Util.isNull(value); } return actual.equals(value); } @@ -252,20 +254,20 @@ public boolean equal(int index, String path, @Nullable Object value) { throw new IndexOutOfBoundsException("Index " + index + " is out of bounds for this array!"); } T arrayEntry = get(index); - if (isNull(arrayEntry)) { - return isNull(value); + if (Util.isNull(arrayEntry)) { + return Util.isNull(value); } if (!(arrayEntry instanceof JSONObject || arrayEntry instanceof Ason)) { throw new InvalidPathException( "You cannot use equal(int, String, " - + "Object) in com.afollestad.ason.AsonArray when the array contains primitives (" + + "Object) in AsonArray when the array contains primitives (" + arrayEntry.getClass().getName() + ")."); } JSONObject encloser = ((Ason) arrayEntry).toStockJson(); Object pathValue = getPathValue(encloser, path, splitPath(path)); - if (isNull(pathValue)) { - return isNull(value); + if (Util.isNull(pathValue)) { + return Util.isNull(value); } return pathValue.equals(value); } diff --git a/src/main/java/com/afollestad/ason/AsonIgnore.java b/src/main/java/com/afollestad/ason/AsonIgnore.java index b84be32..9eabe2e 100644 --- a/src/main/java/com/afollestad/ason/AsonIgnore.java +++ b/src/main/java/com/afollestad/ason/AsonIgnore.java @@ -6,7 +6,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ @Retention(RUNTIME) @Target({FIELD}) -public @interface AsonIgnore {} +public @interface AsonIgnore { + +} diff --git a/src/main/java/com/afollestad/ason/AsonName.java b/src/main/java/com/afollestad/ason/AsonName.java index c93edfc..60f0290 100644 --- a/src/main/java/com/afollestad/ason/AsonName.java +++ b/src/main/java/com/afollestad/ason/AsonName.java @@ -6,7 +6,9 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ @Retention(RUNTIME) @Target({FIELD}) public @interface AsonName { diff --git a/src/main/java/com/afollestad/ason/AsonSerializer.java b/src/main/java/com/afollestad/ason/AsonSerializer.java index 533b876..bae4f73 100644 --- a/src/main/java/com/afollestad/ason/AsonSerializer.java +++ b/src/main/java/com/afollestad/ason/AsonSerializer.java @@ -10,7 +10,6 @@ import java.lang.reflect.Array; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -19,7 +18,9 @@ import org.json.JSONArray; import org.json.JSONObject; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ @SuppressWarnings({"unchecked", "WeakerAccess", "unused"}) class AsonSerializer { @@ -38,52 +39,30 @@ public static AsonSerializer get() { return serializer; } - static List getDeclaredFields(Class cls, boolean recursive) { - Field[] declaredFields = cls.getDeclaredFields(); - List currentFields; - if (declaredFields == null || declaredFields.length == 0) { - currentFields = new ArrayList<>(0); - } else { - currentFields = new ArrayList<>(declaredFields.length); - Collections.addAll(currentFields, declaredFields); - } - if (!recursive || cls.getSuperclass() == null || cls.getSuperclass() == Object.class) { - return currentFields; - } - currentFields.addAll(getDeclaredFields(cls.getSuperclass(), true)); - return currentFields; - } - // ////// SERIALIZE // @Nullable public Ason serialize(@Nullable Object object) { - return serialize(object, false); - } - - @Nullable - public Ason serialize(@Nullable Object object, boolean recursive) { - if (isNull(object)) { + if (Util.isNull(object)) { return null; } else if (object instanceof Ason || object instanceof AsonArray || object instanceof JSONObject || object instanceof JSONArray) { - throw new IllegalArgumentException( - "You cannot serialize com.afollestad.ason.Ason or com.afollestad.ason.AsonArray."); + throw new IllegalArgumentException("You cannot serialize Ason or AsonArray."); } else if (isPrimitive(object)) { throw new IllegalArgumentException( "You cannot serialize primitive types (" + object.getClass().getName() + ")."); } else if (object.getClass().isArray()) { throw new IllegalArgumentException( - "Use com.afollestad.ason.Ason.serialize(Object, Class) to serialize arrays."); + "Use Ason.serialize(Object, Class) to serialize arrays."); } else if (isList(object.getClass())) { throw new IllegalArgumentException( - "Use com.afollestad.ason.Ason.serialize(Object, Class) to serialize lists."); + "Use Ason.serialize(Object, Class) to serialize lists."); } else { - final List fields = getDeclaredFields(object.getClass(), recursive); + final Field[] fields = object.getClass().getDeclaredFields(); final Ason ason = new Ason(); for (Field field : fields) { field.setAccessible(true); @@ -99,11 +78,6 @@ public Ason serialize(@Nullable Object object, boolean recursive) { @Nullable public AsonArray serializeArray(@Nullable Object arrayObject) { - return serializeArray(arrayObject, false); - } - - @Nullable - public AsonArray serializeArray(@Nullable Object arrayObject, boolean recursive) { if (isNull(arrayObject)) { return null; } @@ -129,7 +103,7 @@ public AsonArray serializeArray(@Nullable Object arrayObject, boolean recursive) result.add(value); continue; } - result.add(serialize(value, recursive)); + result.add(serialize(value)); } return result; @@ -137,11 +111,6 @@ public AsonArray serializeArray(@Nullable Object arrayObject, boolean recursive) @Nullable public AsonArray serializeList(@Nullable List list) { - return serializeList(list, false); - } - - @Nullable - public AsonArray serializeList(@Nullable List list, boolean recursive) { if (isNull(list)) { return null; } else if (list.isEmpty()) { @@ -153,7 +122,7 @@ public AsonArray serializeList(@Nullable List list, boolean recursive) { for (int i = 0; i < list.size(); i++) { Array.set(array, i, list.get(i)); } - return serializeArray(array, recursive); + return serializeArray(array); } Object serializeField(final Field field, final Object object) { @@ -188,11 +157,6 @@ Object serializeField(final Field field, final Object object) { @Nullable public T deserialize(@Nullable Ason ason, @NotNull Class cls) { - return deserialize(ason, cls, false); - } - - @Nullable - public T deserialize(@Nullable Ason ason, @NotNull Class cls, boolean recursive) { if (isNull(ason)) { return null; } else if (isPrimitive(cls)) { @@ -209,12 +173,12 @@ public T deserialize(@Nullable Ason ason, @NotNull Class cls, boolean rec ClassCacheEntry cacheEntry = classCache.get(cls.getName()); if (isNull(cacheEntry)) { - cacheEntry = new ClassCacheEntry<>(cls, recursive); + cacheEntry = new ClassCacheEntry<>(cls); classCache.put(cls.getName(), cacheEntry); } final T newObject = cacheEntry.newInstance(); - for (String name : cacheEntry.fields(recursive)) { + for (String name : cacheEntry.fields()) { final Class type = cacheEntry.fieldType(name); if (isPrimitive(type) || type == JSONObject.class @@ -246,18 +210,12 @@ public T deserialize(@Nullable Ason ason, @NotNull Class cls, boolean rec @Nullable public T deserializeArray(@Nullable AsonArray json, @NotNull Class cls) { - return deserializeArray(json, cls, false); - } - - @Nullable - public T deserializeArray( - @Nullable AsonArray json, @NotNull Class cls, boolean recursive) { if (isNull(json)) { return null; } else if (!cls.isArray() && cls != Object.class) { if (isList(cls)) { throw new IllegalArgumentException( - "Use com.afollestad.ason.Ason.deserializeList() for Lists, not deserializeArray()."); + "Use Ason.deserializeList() for Lists, not deserializeArray()."); } throw new IllegalArgumentException(cls.getName() + " is not an array type."); } @@ -285,14 +243,14 @@ public T deserializeArray( Array.set(newArray, i, item); } else if (itemType.isArray()) { AsonArray subArray = (AsonArray) item; - Array.set(newArray, i, deserializeArray(subArray, component, recursive)); + Array.set(newArray, i, deserializeArray(subArray, component)); } else if (isList(itemType)) { AsonArray subArray = (AsonArray) item; if (subArray.isEmpty()) { Array.set(newArray, i, new ArrayList(0)); } else { Class listComponent = subArray.get(0).getClass(); - Array.set(newArray, i, deserializeList(subArray, listComponent, recursive)); + Array.set(newArray, i, deserializeList(subArray, listComponent)); } } else if (!(item instanceof Ason)) { throw new IllegalStateException( @@ -304,7 +262,7 @@ public T deserializeArray( + " objects instead."); } else { Ason subObject = (Ason) item; - Array.set(newArray, i, deserialize(subObject, itemType, recursive)); + Array.set(newArray, i, deserialize(subObject, itemType)); } } @@ -313,12 +271,6 @@ public T deserializeArray( @Nullable public List deserializeList(@Nullable AsonArray json, @NotNull Class cls) { - return deserializeList(json, cls, false); - } - - @Nullable - public List deserializeList( - @Nullable AsonArray json, @NotNull Class cls, boolean recursive) { if (isNull(json)) { return null; } else if (json.isEmpty()) { @@ -326,7 +278,7 @@ public List deserializeList( } Class arrayType = Array.newInstance(cls, 0).getClass(); - Object array = deserializeArray(json, arrayType, recursive); + Object array = deserializeArray(json, arrayType); int length = Array.getLength(array); List result = new ArrayList<>(); diff --git a/src/main/java/com/afollestad/ason/ClassCacheEntry.java b/src/main/java/com/afollestad/ason/ClassCacheEntry.java index 72ca654..f028646 100644 --- a/src/main/java/com/afollestad/ason/ClassCacheEntry.java +++ b/src/main/java/com/afollestad/ason/ClassCacheEntry.java @@ -1,6 +1,5 @@ package com.afollestad.ason; -import static com.afollestad.ason.AsonSerializer.getDeclaredFields; import static com.afollestad.ason.Util.fieldName; import static com.afollestad.ason.Util.getDefaultConstructor; import static com.afollestad.ason.Util.listGenericType; @@ -13,28 +12,23 @@ import java.util.List; import java.util.Set; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ class ClassCacheEntry { - private boolean gotRecursiveFields; private final Class cls; private final Constructor ctor; private final HashMap fieldMap; private final HashMap> listGenericTypeMap; - ClassCacheEntry(Class cls, boolean recursive) { + ClassCacheEntry(Class cls) { this.cls = cls; this.fieldMap = new HashMap<>(4); this.ctor = getDefaultConstructor(cls); this.listGenericTypeMap = new HashMap<>(0); - invalidateFields(recursive); - } - private void invalidateFields(boolean recursive) { - if (recursive) { - this.gotRecursiveFields = true; - } - final List fields = getDeclaredFields(cls, recursive); + final Field[] fields = cls.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); if (shouldIgnore(field)) { @@ -48,10 +42,7 @@ private void invalidateFields(boolean recursive) { } } - Set fields(boolean recursive) { - if (!gotRecursiveFields && recursive) { - invalidateFields(true); - } + Set fields() { return fieldMap.keySet(); } diff --git a/src/main/java/com/afollestad/ason/InvalidJsonException.java b/src/main/java/com/afollestad/ason/InvalidJsonException.java index 131e279..4aa334b 100644 --- a/src/main/java/com/afollestad/ason/InvalidJsonException.java +++ b/src/main/java/com/afollestad/ason/InvalidJsonException.java @@ -1,6 +1,8 @@ package com.afollestad.ason; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ public class InvalidJsonException extends IllegalArgumentException { InvalidJsonException(String json, Exception inner) { diff --git a/src/main/java/com/afollestad/ason/InvalidPathException.java b/src/main/java/com/afollestad/ason/InvalidPathException.java index b4f9d75..3712bd3 100644 --- a/src/main/java/com/afollestad/ason/InvalidPathException.java +++ b/src/main/java/com/afollestad/ason/InvalidPathException.java @@ -1,6 +1,8 @@ package com.afollestad.ason; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ public class InvalidPathException extends IllegalArgumentException { InvalidPathException(String message) { diff --git a/src/main/java/com/afollestad/ason/Util.java b/src/main/java/com/afollestad/ason/Util.java index 91ed181..2024de2 100644 --- a/src/main/java/com/afollestad/ason/Util.java +++ b/src/main/java/com/afollestad/ason/Util.java @@ -9,11 +9,13 @@ import org.json.JSONArray; import org.json.JSONObject; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ class Util { Util() { - throw new IllegalStateException("com.afollestad.ason.Util shouldn't be constructed!"); + throw new IllegalStateException("Util shouldn't be constructed!"); } static String[] splitPath(String key) { @@ -239,11 +241,8 @@ static boolean isList(Class cls) { } static boolean shouldIgnore(Field field) { - return field.isSynthetic() // synthetic fields - || field.getName().startsWith("this$") + return field.getName().startsWith("this$") || field.getName().equals("$jacocoData") // used with Jacoco testing - || field.getName().equals("$change") // used by Instant run in Android Studio - || field.getName().equals("serialVersionUID") || field.getAnnotation(AsonIgnore.class) != null; } diff --git a/src/test/java/com/afollestad/ason/AsonArrayTest.java b/src/test/java/com/afollestad/ason/AsonArrayTest.java index 912e5df..8e3f382 100644 --- a/src/test/java/com/afollestad/ason/AsonArrayTest.java +++ b/src/test/java/com/afollestad/ason/AsonArrayTest.java @@ -1,10 +1,10 @@ package com.afollestad.ason; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.List; @@ -20,12 +20,16 @@ public void setup() { array = new AsonArray() .add(new Ason().put("_id", 1).put("name", "Aidan").put("attrs.priority", 2)) - .add(new Ason().put("_id", 2).put("name", "Nina").put("attrs.priority", 1)); + .add(new Ason().put("_id", 2).put("name", "Waverly").put("attrs.priority", 1)); } - @Test(expected = InvalidJsonException.class) + @Test public void invalid_json_test() { - new AsonArray<>("Hello, world!"); + try { + new AsonArray<>("Hello, world!"); + assertFalse("No exception thrown for invalid JSON!", false); + } catch (InvalidJsonException ignored) { + } } @Test @@ -37,31 +41,39 @@ public void empty_json_test() { @Test public void out_of_bounds_test() { AsonArray array = new AsonArray().add(1, 2, 3, 4); - assertNull(array.get(9)); + try { + array.get(9); + assertFalse("No exception was thrown for an out of bounds index!", false); + } catch (IndexOutOfBoundsException ignored) { + } try { array.getJsonArray(9); - fail("No exception was thrown for an out of bounds index!"); + assertFalse("No exception was thrown for an out of bounds index!", false); } catch (IndexOutOfBoundsException ignored) { } try { array.getJsonObject(9); - fail("No exception was thrown for an out of bounds index!"); + assertFalse("No exception was thrown for an out of bounds index!", false); + } catch (IndexOutOfBoundsException ignored) { + } + try { + array.equal(9, 21); + assertFalse("No exception was thrown for an out of bounds index!", false); } catch (IndexOutOfBoundsException ignored) { } - assertTrue(array.equal(9, null)); try { array.remove(20); - fail("No exception was thrown for an out of bounds index!"); + assertFalse("No exception was thrown for an out of bounds index!", false); } catch (IndexOutOfBoundsException ignored) { } try { array.equal(21, "name", "Aidan"); - fail("No exception was thrown for an out of bounds index!"); + assertFalse("No exception was thrown for an out of bounds index!", false); } catch (IndexOutOfBoundsException ignored) { } try { array.get(21, "name", Integer.class); - fail("No exception was thrown for an out of bounds index!"); + assertFalse("No exception was thrown for an out of bounds index!", false); } catch (IndexOutOfBoundsException ignored) { } } @@ -106,7 +118,7 @@ public void put_null_test() { public void builder_test() { String expected = "[{\"name\":\"Aidan\",\"_id\":1,\"attrs\":{\"priority\":2}}," - + "{\"name\":\"Nina\",\"_id\":2,\"attrs\":{\"priority\":1}}]"; + + "{\"name\":\"Waverly\",\"_id\":2,\"attrs\":{\"priority\":1}}]"; assertEquals(array.toString(), expected); } @@ -118,7 +130,7 @@ public void from_string_test() { assertTrue(array.equal(0, "_id", 1)); assertTrue(array.equal(0, "attrs.priority", 2)); - assertTrue(array.equal(1, "name", "Nina")); + assertTrue(array.equal(1, "name", "Waverly")); assertTrue(array.equal(1, "_id", 2)); assertTrue(array.equal(1, "attrs.priority", 1)); } @@ -126,7 +138,7 @@ public void from_string_test() { @Test public void remove_test() { Ason one = new Ason().put("_id", 1).put("name", "Aidan").put("attrs.priority", 2); - Ason two = new Ason().put("_id", 2).put("name", "Nina").put("attrs.priority", 1); + Ason two = new Ason().put("_id", 2).put("name", "Waverly").put("attrs.priority", 1); array = new AsonArray().add(one).add(two); array.remove(0); assertEquals(two, array.get(0)); @@ -170,7 +182,7 @@ public void test_array_in_array() { @Test public void test_array_in_array_deserialize() { AsonArray parent = - new AsonArray().add(new Integer[] {1, 2, 3, 4}, new Integer[] {5, 6, 7, 8}); + new AsonArray().add(new Integer[]{1, 2, 3, 4}, new Integer[]{5, 6, 7, 8}); assertEquals(2, parent.size()); Integer[] arrayOne = parent.get(0, Integer[].class); @@ -202,25 +214,34 @@ public void test_iterator() { @Test public void deep_equal_test() { Ason one = new Ason().put("name", "Aidan").put("born", 1995); - Ason two = new Ason().put("name", "Nina").put("born", 1997); + Ason two = new Ason().put("name", "Waverly").put("born", 1997); AsonArray array = new AsonArray().add(one, two).addNull(); assertTrue(array.equal(0, "name", "Aidan")); - assertTrue(array.equal(1, "name", "Nina")); + assertTrue(array.equal(1, "name", "Waverly")); assertTrue(array.equal(0, "idk", null)); assertTrue(array.equal(2, "idk", null)); } - @Test(expected = InvalidPathException.class) + @Test public void primitive_equal_deep_error_test() { AsonArray idk = new AsonArray().add(1, 2, 3, 4); - idk.equal(0, "name", "Aidan"); + try { + idk.equal(0, "name", "Aidan"); + assertFalse( + "An exception was not thrown when using path equality on a primitive array!", false); + } catch (InvalidPathException ignored) { + } } @SuppressWarnings("unchecked") - @Test(expected = IllegalStateException.class) + @Test public void test_get_with_path_on_primitive() { AsonArray array = new AsonArray().add(1, 2, 3, 4); - array.get(2, "idk.name", SimpleTestDataOne.class); + try { + array.get(2, "idk.name", SimpleTestDataOne.class); + assertFalse("No exception was thrown!", false); + } catch (IllegalStateException ignored) { + } } @Test @@ -283,21 +304,33 @@ public void test_get_list_null_items() { assertNull(array.getList(1, Integer.class)); } - @Test(expected = IllegalStateException.class) + @Test public void test_get_list_non_array_items() { AsonArray array = new AsonArray().add(1, 2, 3, 4); - array.getList(0, Integer.class); + try { + array.getList(0, Integer.class); + assertFalse("No exception was thrown!", false); + } catch (IllegalStateException ignored) { + } } - @Test(expected = IllegalArgumentException.class) + @Test public void test_get_list_wrong_cls() { AsonArray array = new AsonArray().add(1, 2, 3, 4); - array.getList(0, List.class); + try { + array.getList(0, List.class); + assertFalse("No exception was thrown!", false); + } catch (IllegalArgumentException ignored) { + } } - @Test(expected = IllegalStateException.class) + @Test public void test_regular_get_list() { AsonArray array = new AsonArray().addNull().addNull(); - array.get(0, List.class); + try { + array.get(0, List.class); + assertFalse("No exception was thrown!", false); + } catch (IllegalStateException ignored) { + } } } diff --git a/src/test/java/com/afollestad/ason/AsonPathTest.java b/src/test/java/com/afollestad/ason/AsonPathTest.java index 8da97fc..f314f3f 100644 --- a/src/test/java/com/afollestad/ason/AsonPathTest.java +++ b/src/test/java/com/afollestad/ason/AsonPathTest.java @@ -19,7 +19,10 @@ public void test_split_path_no_components() { @Test public void builder_test() { - Ason ason = new Ason().put("person._id", 3).put("person.name", "Aidan").put("person.age", 21); + Ason ason = new Ason() + .put("person._id", 3) + .put("person.name", "Aidan") + .put("person.age", 21); assertEquals(3, ason.get("person._id")); assertEquals("Aidan", ason.get("person.name")); @@ -31,90 +34,84 @@ public void builder_test() { @Test public void builder_index_test_one() { - Ason ason = - new Ason() - .put("_id", 3) - .put("name", "Aidan") - .put("pets.$0", "Kierra") - .put("pets.$1", "Elijah") - .put("pets.$2", "Olivia"); - assertEquals( - "{\"pets\":" + "[\"Kierra\",\"Elijah\",\"Olivia\"]," + "\"name\":\"Aidan\",\"_id\":3}", - ason.toString()); + Ason ason = new Ason() + .put("_id", 3) + .put("name", "Aidan") + .put("pets.$0", "Kierra") + .put("pets.$1", "Elijah") + .put("pets.$2", "Olivia"); + assertEquals("{\"pets\":" + + "[\"Kierra\",\"Elijah\",\"Olivia\"]," + + "\"name\":\"Aidan\",\"_id\":3}", ason.toString()); } @Test public void builder_index_test_two() { - Ason ason = - new Ason() - .put("_id", 3) - .put("name", "Aidan") - .put("pets.$0.id", 1) - .put("pets.$0.name", "Kierra") - .put("pets.$1.id", 2) - .put("pets.$1.name", "Elijah") - .put("pets.$2.id", 3) - .put("pets.$2.name", "Olivia"); - assertEquals( - "{\"pets\":[" - + "{\"name\":\"Kierra\",\"id\":1}," - + "{\"name\":\"Elijah\",\"id\":2}," - + "{\"name\":\"Olivia\",\"id\":3}]," - + "\"name\":\"Aidan\",\"_id\":3}", - ason.toString()); + Ason ason = new Ason() + .put("_id", 3) + .put("name", "Aidan") + .put("pets.$0.id", 1) + .put("pets.$0.name", "Kierra") + .put("pets.$1.id", 2) + .put("pets.$1.name", "Elijah") + .put("pets.$2.id", 3) + .put("pets.$2.name", "Olivia"); + assertEquals("{\"pets\":[" + + "{\"name\":\"Kierra\",\"id\":1}," + + "{\"name\":\"Elijah\",\"id\":2}," + + "{\"name\":\"Olivia\",\"id\":3}]," + + "\"name\":\"Aidan\",\"_id\":3}", ason.toString()); } @Test public void builder_index_test_three() { - Ason ason = - new Ason() - .put("_id", 1) - .put("people.$0.name", "Aidan") - .put("people.$0.pets.$0", "Kierra") - .put("people.$0.pets.$1", "Elijah") - .put("people.$0.pets.$2", "Olivia"); - assertEquals( - "{\"_id\":1," - + "\"people\":[" - + "{\"pets\":" - + "[\"Kierra\",\"Elijah\",\"Olivia\"]," - + "\"name\":\"Aidan\"}" - + "]" - + "}", - ason.toString()); + Ason ason = new Ason() + .put("_id", 1) + .put("people.$0.name", "Aidan") + .put("people.$0.pets.$0", "Kierra") + .put("people.$0.pets.$1", "Elijah") + .put("people.$0.pets.$2", "Olivia"); + assertEquals("{\"_id\":1," + + "\"people\":[" + + "{\"pets\":" + + "[\"Kierra\",\"Elijah\",\"Olivia\"]," + + "\"name\":\"Aidan\"}" + + "]" + + "}", ason.toString()); } @Test public void builder_index_test_four() { - Ason ason = - new Ason() - .put("_id", 1) - .put("people.$0.name", "Aidan") - .put("people.$0.id", 1) - .put("people.$0.pets.$0.name", "Kierra") - .put("people.$0.pets.$0.id", 1) - .put("people.$0.pets.$1.name", "Elijah") - .put("people.$0.pets.$1.id", 2); - assertEquals( - "{\"_id\":1," - + "\"people\":[" - + "{\"pets\":" - + "[{\"name\":\"Kierra\",\"id\":1}," - + "{\"name\":\"Elijah\",\"id\":2}]," - + "\"name\":\"Aidan\"," - + "\"id\":1}]}", - ason.toString()); + Ason ason = new Ason() + .put("_id", 1) + .put("people.$0.name", "Aidan") + .put("people.$0.id", 1) + .put("people.$0.pets.$0.name", "Kierra") + .put("people.$0.pets.$0.id", 1) + .put("people.$0.pets.$1.name", "Elijah") + .put("people.$0.pets.$1.id", 2); + assertEquals("{\"_id\":1," + + "\"people\":[" + + "{\"pets\":" + + "[{\"name\":\"Kierra\",\"id\":1}," + + "{\"name\":\"Elijah\",\"id\":2}]," + + "\"name\":\"Aidan\"," + + "\"id\":1}]}", ason.toString()); } @Test public void builder_index_test_five() { - Ason ason = new Ason().put("_id", 1).put("props.$0", 1, 2, 3, 4); + Ason ason = new Ason() + .put("_id", 1) + .put("props.$0", 1, 2, 3, 4); assertEquals("{\"_id\":1,\"props\":[[1,2,3,4]]}", ason.toString()); } @Test public void builder_index_test_six() { - Ason ason = new Ason().put("_id", 1).put("props.$0.$0", 1, 2, 3, 4); + Ason ason = new Ason() + .put("_id", 1) + .put("props.$0.$0", 1, 2, 3, 4); assertEquals("{\"_id\":1,\"props\":[[[1,2,3,4]]]}", ason.toString()); } @@ -131,17 +128,14 @@ public void from_string_test() { @Test public void anon_fields_test() { - Ason ason = - new Ason() { - @AsonName(name = "person._id") - int id = 3; - - @AsonName(name = "person.name") - String name = "Aidan"; - - @AsonName(name = "person.age") - int age = 21; - }; + Ason ason = new Ason() { + @AsonName(name = "person._id") + int id = 3; + @AsonName(name = "person.name") + String name = "Aidan"; + @AsonName(name = "person.age") + int age = 21; + }; assertEquals(ason.size(), 1); assertEquals(3, ason.get("person._id")); @@ -154,13 +148,12 @@ public void anon_fields_test() { @Test public void array_get_path_test() { - String input = - "[{\"body\":\"Hello, world\",\"sender\":{\"name\":\"Aidan\",\"id\":2}}," - + "{\"body\":\"Hello, world\",\"sender\":{\"name\":\"Nina\",\"id\":1}}," - + "{\"body\":\"Hello, world\",\"sender\":{\"name\":\"Jeff\",\"id\":3}}]"; + String input = "[{\"body\":\"Hello, world\",\"sender\":{\"name\":\"Aidan\",\"id\":2}}," + + "{\"body\":\"Hello, world\",\"sender\":{\"name\":\"Waverly\",\"id\":1}}," + + "{\"body\":\"Hello, world\",\"sender\":{\"name\":\"Jeff\",\"id\":3}}]"; AsonArray array = new AsonArray(input); - assertEquals("Nina", array.get(1, "sender.name")); + assertEquals("Waverly", array.get(1, "sender.name")); assertEquals(3, array.get(2, "sender.id")); } @@ -173,57 +166,54 @@ public void test_escape_period() { @Test public void test_index_notation() { - String input = - "{\"group_id\":1,\"title\":\"Hello, world!\"," - + "\"participants\":[{\"name\":\"Aidan\",\"id\":2}," - + "{\"name\":\"Nina\",\"id\":1}]}"; + String input = "{\"group_id\":1,\"title\":\"Hello, world!\"," + + "\"participants\":[{\"name\":\"Aidan\",\"id\":2}," + + "{\"name\":\"Waverly\",\"id\":1}]}"; Ason object = new Ason(input); - assertEquals("Nina", object.get("participants.$1.name")); + assertEquals("Waverly", object.get("participants.$1.name")); assertEquals(2, object.get("participants.$0.id")); } @Test public void test_escape_dollarsign() { - String input = "{\"participants\":{\"$1\":{\"name\":\"Nina\"}}}"; + String input = "{\"participants\":{\"$1\":{\"name\":\"Waverly\"}}}"; Ason object = new Ason(input); - assertEquals("Nina", object.get("participants.\\$1.name")); + assertEquals("Waverly", object.get("participants.\\$1.name")); } @Test public void test_remove_dot_notation() { - Ason ason = - new Ason() - .put("_id", 3) - .put("name", "Aidan") - .put("age", 21) - .put("spouse.name", "Nina") - .put("spouse.age", 19); + Ason ason = new Ason() + .put("_id", 3) + .put("name", "Aidan") + .put("age", 21) + .put("spouse.name", "Waverly") + .put("spouse.age", 19); ason.remove("spouse.age"); ason.remove("spouse.nonexisting.test"); // nothing should happen here - assertEquals( - "{\"name\":\"Aidan\",\"_id\":3,\"age\":21," + "\"spouse\":{\"name\":\"Nina\"}}", - ason.toString()); + assertEquals("{\"name\":\"Aidan\",\"_id\":3,\"age\":21," + + "\"spouse\":{\"name\":\"Waverly\"}}", ason.toString()); } @Test public void test_remove_index_notation() { - String input = - "{\"group_id\":1,\"title\":\"Hello, world!\"," - + "\"participants\":[{\"name\":\"Aidan\",\"id\":2}," - + "{\"name\":\"Nina\",\"id\":1}]}"; + String input = "{\"group_id\":1,\"title\":\"Hello, world!\"," + + "\"participants\":[{\"name\":\"Aidan\",\"id\":2}," + + "{\"name\":\"Waverly\",\"id\":1}]}"; Ason object = new Ason(input); object.remove("participants.$0"); AsonArray participants = object.get("participants"); assertEquals(participants.size(), 1); assertEquals(participants.get(0).get("id"), 1); - assertEquals(participants.get(0).get("name"), "Nina"); + assertEquals(participants.get(0).get("name"), "Waverly"); } @Test public void test_index_notation_add_array() { - Ason ason = new Ason().put("person.props", 1, 2, 3, 4); + Ason ason = new Ason() + .put("person.props", 1, 2, 3, 4); ason.put("person.props.$4", 5); ason.put("person.props.$1", 6); assertEquals("{\"person\":{\"props\":[1,6,3,4,5]}}", ason.toString()); @@ -231,30 +221,37 @@ public void test_index_notation_add_array() { @Test public void test_put_null_path() { - Ason ason = new Ason().putNull("test1").putNull("test2.test3").putNull("person.spouse.name"); + Ason ason = new Ason() + .putNull("test1") + .putNull("test2.test3") + .putNull("person.spouse.name"); assertNull(ason.get("test.test3")); assertNull(ason.get("test1.test")); assertNull(ason.get("test2.test3.test4")); assertNotNull(ason.getJsonObject("person")); - assertNotNull(ason.getJsonObject("person").getJsonObject("spouse")); - assertNull(ason.getJsonObject("person").getJsonObject("spouse").getString("name")); + assertNotNull(ason.getJsonObject("person") + .getJsonObject("spouse")); + assertNull(ason.getJsonObject("person") + .getJsonObject("spouse") + .getString("name")); } @Test public void test_mid_path_null() { - Ason ason = - new Ason() - .put("person.name", "Aidan") - .put("person.born", 1995) - .put("person.spouse.name", "Nina"); + Ason ason = new Ason() + .put("person.name", "Aidan") + .put("person.born", 1995) + .put("person.spouse.name", "Waverly"); assertEquals("Aidan", ason.get("person.name")); assertNull(ason.get("person.spouse.spouse.age")); } @Test public void test_index_notation_mid_null() { - Ason ason = - new Ason().putNull("person.family").putNull("person.props.$0").putNull("person.props.$1"); + Ason ason = new Ason() + .putNull("person.family") + .putNull("person.props.$0") + .putNull("person.props.$1"); assertNull(ason.get("person.family")); assertNull(ason.get("person.family.$0")); assertNotNull(ason.get("person.props")); @@ -263,29 +260,50 @@ public void test_index_notation_mid_null() { assertNull(ason.get("person.props.$2")); } - @Test(expected = InvalidPathException.class) + @Test public void test_error_get_array_keyname() { - AsonArray array = new AsonArray().add("Aidan", "Nina", "Natalie", "Jeff"); - Ason ason = new Ason().put("array", array); - ason.get("array.$1i"); + AsonArray array = new AsonArray() + .add("Aidan", "Waverly", "Natalie", "Jeff"); + Ason ason = new Ason() + .put("array", array); + try { + ason.get("array.$1i"); + assertFalse("No error was thrown for attempting" + + " to retrieve a value from an array using a name key!", false); + } catch (InvalidPathException ignored) { + } } @Test public void test_index_notation_get_value() { - Ason one = new Ason().put("id", 2).put("name", "Aidan"); - Ason two = new Ason().put("id", 3).put("name", "Nina"); - Ason three = new Ason().put("id", 4).put("name", "Natalie"); - Ason four = new Ason().put("id", 5).put("name", "Jeff"); - AsonArray array = new AsonArray().add(one, two, three, four); - Ason child1 = new Ason().put("array", array); - Ason parent = new Ason().put("id", 1).put("child1", child1); + Ason one = new Ason() + .put("id", 2) + .put("name", "Aidan"); + Ason two = new Ason() + .put("id", 3) + .put("name", "Waverly"); + Ason three = new Ason() + .put("id", 4) + .put("name", "Natalie"); + Ason four = new Ason() + .put("id", 5) + .put("name", "Jeff"); + AsonArray array = new AsonArray() + .add(one, two, three, four); + Ason child1 = new Ason() + .put("array", array); + Ason parent = new Ason() + .put("id", 1) + .put("child1", child1); assertEquals("Jeff", parent.get("child1.array.$3.name")); assertNull(parent.get("child1.array.$4.name.idk")); } @Test public void test_path_on_primitive() { - Ason ason = new Ason().put("id", 2).put("test.id", 3); + Ason ason = new Ason() + .put("id", 2) + .put("test.id", 3); try { ason.get("id.name"); assertFalse("No exception was thrown for using a path on a primitive entry!", false); @@ -308,15 +326,22 @@ public void test_path_on_primitive() { } } - @Test(expected = InvalidPathException.class) + @Test public void test_index_notation_on_parent_object() { - Ason ason = new Ason().put("person.name", "Aidan").put("person.born", 1995); - ason.get("person.$0.test"); + Ason ason = new Ason() + .put("person.name", "Aidan") + .put("person.born", 1995); + try { + ason.get("person.$0.test"); + assertFalse("No exception thrown for using index notation on a parent object!", false); + } catch (InvalidPathException ignored) { + } } @Test public void test_put_path_existing_obj() { - Ason ason = new Ason().put("person.id", 1); + Ason ason = new Ason() + .put("person.id", 1); ason.put("person.idk", 4); assertEquals("{\"person\":{\"idk\":4,\"id\":1}}", ason.toString()); } diff --git a/src/test/java/com/afollestad/ason/AsonPrimitivesTest.java b/src/test/java/com/afollestad/ason/AsonPrimitivesTest.java index 807f241..87ed9f9 100644 --- a/src/test/java/com/afollestad/ason/AsonPrimitivesTest.java +++ b/src/test/java/com/afollestad/ason/AsonPrimitivesTest.java @@ -15,7 +15,7 @@ public class AsonPrimitivesTest { @Test public void short_test() { - AsonArray result = Ason.serializeArray(new short[] {1, 2, 3, 4}); + AsonArray result = Ason.serializeArray(new short[]{1, 2, 3, 4}); String output = result.toString(); assertEquals("[1,2,3,4]", output); @@ -28,7 +28,7 @@ public void short_test() { @Test public void int_test() { - AsonArray result = Ason.serializeArray(new int[] {1, 2, 3, 4}); + AsonArray result = Ason.serializeArray(new int[]{1, 2, 3, 4}); String output = result.toString(); assertEquals("[1,2,3,4]", output); @@ -41,7 +41,7 @@ public void int_test() { @Test public void long_test() { - AsonArray result = Ason.serializeArray(new long[] {1L, 2L, 3L, 4L}); + AsonArray result = Ason.serializeArray(new long[]{1L, 2L, 3L, 4L}); String output = result.toString(); assertEquals("[1,2,3,4]", output); @@ -54,7 +54,7 @@ public void long_test() { @Test public void float_test() { - AsonArray result = Ason.serializeArray(new float[] {1f, 2f, 3f, 4f}); + AsonArray result = Ason.serializeArray(new float[]{1f, 2f, 3f, 4f}); String output = result.toString(); assertEquals("[1,2,3,4]", output); @@ -67,7 +67,7 @@ public void float_test() { @Test public void double_test() { - AsonArray result = Ason.serializeArray(new double[] {1d, 2d, 3d, 4d}); + AsonArray result = Ason.serializeArray(new double[]{1d, 2d, 3d, 4d}); String output = result.toString(); assertEquals("[1,2,3,4]", output); @@ -80,7 +80,7 @@ public void double_test() { @Test public void char_test() { - AsonArray result = Ason.serializeArray(new char[] {'a', 'b', 'c', 'd'}); + AsonArray result = Ason.serializeArray(new char[]{'a', 'b', 'c', 'd'}); String output = result.toString(); assertEquals("[\"a\",\"b\",\"c\",\"d\"]", output); @@ -93,7 +93,7 @@ public void char_test() { @Test public void byte_test() { - AsonArray result = Ason.serializeArray(new byte[] {1, 2, 3, 4}); + AsonArray result = Ason.serializeArray(new byte[]{1, 2, 3, 4}); String output = result.toString(); assertEquals("[1,2,3,4]", output); @@ -106,7 +106,7 @@ public void byte_test() { @Test public void boolean_test() { - AsonArray result = Ason.serializeArray(new boolean[] {true, false, true, false}); + AsonArray result = Ason.serializeArray(new boolean[]{true, false, true, false}); String output = result.toString(); assertEquals("[true,false,true,false]", output); diff --git a/src/test/java/com/afollestad/ason/AsonSerializeTest.java b/src/test/java/com/afollestad/ason/AsonSerializeTest.java index 3126389..93cb52e 100644 --- a/src/test/java/com/afollestad/ason/AsonSerializeTest.java +++ b/src/test/java/com/afollestad/ason/AsonSerializeTest.java @@ -15,87 +15,89 @@ import org.json.JSONObject; import org.junit.Test; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ public class AsonSerializeTest { - // - ////// SERIALIZE - // - @Test public void test_serialize() { - Person person = new Person(2, "Aidan", 22); - person.spouse = new Person(6, "Nina", 22); + Person person = new Person(2, "Aidan", 21); + person.spouse = new Person(6, "Waverly", 19); Ason ason = Ason.serialize(person); assertEquals("Aidan", ason.get("name")); assertEquals(2, ason.get("_id")); - assertEquals(22, ason.get("age")); + assertEquals(21, ason.get("age")); Ason spouse = ason.get("spouse"); - assertEquals("Nina", spouse.get("name")); + assertEquals("Waverly", spouse.get("name")); assertEquals(6, spouse.get("_id")); - assertEquals(22, spouse.get("age")); + assertEquals(19, spouse.get("age")); } @Test public void test_serialize_array() { - Person[] people = new Person[] {new Person(1, "Aidan", 22), new Person(2, "Nina", 22)}; + Person[] people = new Person[]{new Person(1, "Aidan", 21), new Person(2, "Waverly", 19)}; AsonArray json = Ason.serializeArray(people); Ason one = json.getJsonObject(0); assertEquals("Aidan", one.get("name")); assertEquals(1, one.get("_id")); - assertEquals(22, one.get("age")); + assertEquals(21, one.get("age")); Ason two = json.getJsonObject(1); - assertEquals("Nina", two.get("name")); + assertEquals("Waverly", two.get("name")); assertEquals(2, two.get("_id")); - assertEquals(22, two.get("age")); + assertEquals(19, two.get("age")); } @Test public void test_serialize_list() { List people = new ArrayList<>(2); - people.add(new Person(1, "Aidan", 22)); - people.add(new Person(2, "Nina", 22)); + people.add(new Person(1, "Aidan", 21)); + people.add(new Person(2, "Waverly", 19)); AsonArray json = Ason.serializeList(people); Ason one = json.getJsonObject(0); assertEquals("Aidan", one.get("name")); assertEquals(1, one.get("_id")); - assertEquals(22, one.get("age")); + assertEquals(21, one.get("age")); Ason two = json.getJsonObject(1); - assertEquals("Nina", two.get("name")); + assertEquals("Waverly", two.get("name")); assertEquals(2, two.get("_id")); - assertEquals(22, two.get("age")); + assertEquals(19, two.get("age")); } + // + ////// SERIALIZE + // + @Test public void test_put_object_serialize() { Ason object = new Ason(); - Person person = new Person(1, "Aidan", 22); + Person person = new Person(1, "Aidan", 21); object.put("person", person); assertEquals("Aidan", object.get("person.name")); assertEquals(1, object.get("person._id")); - assertEquals(22, object.get("person.age")); + assertEquals(21, object.get("person.age")); } @Test public void test_put_array_serialize() { AsonArray array = new AsonArray<>(); - Person person = new Person(1, "Aidan", 22); + Person person = new Person(1, "Aidan", 21); array.add(person); Ason first = array.getJsonObject(0); assertEquals("Aidan", first.get("name")); assertEquals(1, first.get("_id")); - assertEquals(22, first.get("age")); + assertEquals(21, first.get("age")); } @Test public void test_primitive_serialize() { - int[] ids = new int[] {1, 2, 3, 4}; + int[] ids = new int[]{1, 2, 3, 4}; AsonArray array = Ason.serializeArray(ids); assertEquals("[1,2,3,4]", array.toString()); } @@ -103,7 +105,7 @@ public void test_primitive_serialize() { @Test public void test_serialize_with_array() { Person2 person = new Person2(1); - person.family = new Person2[] {new Person2(2), new Person2(3), new Person2(4)}; + person.family = new Person2[]{new Person2(2), new Person2(3), new Person2(4)}; Ason ason = Ason.serialize(person); AsonArray array = ason.get("family"); @@ -124,84 +126,65 @@ public void test_serialize_with_list() { assertEquals(array.size(), 3); } - @Test - public void test_recursive_serialize() { - Superhero person = new Superhero(2, "Aidan", 22, "Flight"); - person.spouse = new Person(6, "Nina", 22); - Ason ason = Ason.serialize(person, true); - assertEquals("Aidan", ason.get("name")); - assertEquals(2, ason.get("_id")); - assertEquals(22, ason.get("age")); - assertEquals("Flight", ason.get("power")); - } - - @Test - public void test_recursive_serialize_only_super_fields() { - EmptyPerson person = new EmptyPerson(2, "Aidan", 22); - person.spouse = new Person(6, "Nina", 22); - Ason ason = Ason.serialize(person, true); - assertEquals("Aidan", ason.get("name")); - assertEquals(2, ason.get("_id")); - assertEquals(22, ason.get("age")); - } - - // - ////// DESERIALIZE - // - @Test public void test_deserialize() { String input = - "{\"name\":\"Aidan\",\"_id\":2,\"age\":22," - + "\"spouse\":{\"name\":\"Nina\",\"_id\":6,\"age\":22}}"; + "{\"name\":\"Aidan\",\"_id\":2,\"age\":21," + + "\"spouse\":{\"name\":\"Waverly\",\"_id\":6,\"age\":19}}"; Ason ason = new Ason(input); Person person = ason.deserialize(Person.class); assertEquals(person.name, "Aidan"); assertEquals(person.id, 2); - assertEquals(person.age, 22); + assertEquals(person.age, 21); - assertEquals(person.spouse.name, "Nina"); + assertEquals(person.spouse.name, "Waverly"); assertEquals(person.spouse.id, 6); - assertEquals(person.spouse.age, 22); + assertEquals(person.spouse.age, 19); } @Test public void test_deserialize_array() { String input = - "[{\"name\":\"Aidan\",\"_id\":1,\"age\":22}," + "{\"name\":\"Nina\",\"_id\":2,\"age\":22}]"; + "[{\"name\":\"Aidan\",\"_id\":1,\"age\":21}," + + "{\"name\":\"Waverly\",\"_id\":2,\"age\":19}]"; AsonArray array = new AsonArray<>(input); Person[] people = array.deserialize(Person[].class); assertEquals(people[0].name, "Aidan"); assertEquals(people[0].id, 1); - assertEquals(people[0].age, 22); + assertEquals(people[0].age, 21); - assertEquals(people[1].name, "Nina"); + assertEquals(people[1].name, "Waverly"); assertEquals(people[1].id, 2); - assertEquals(people[1].age, 22); + assertEquals(people[1].age, 19); } @Test public void test_deserialize_list() { String input = - "[{\"name\":\"Aidan\",\"_id\":1,\"age\":22}," + "{\"name\":\"Nina\",\"_id\":2,\"age\":22}]"; + "[{\"name\":\"Aidan\",\"_id\":1,\"age\":21}," + + "{\"name\":\"Waverly\",\"_id\":2,\"age\":19}]"; AsonArray array = new AsonArray<>(input); List people = array.deserializeList(Person.class); assertEquals(people.get(0).name, "Aidan"); assertEquals(people.get(0).id, 1); - assertEquals(people.get(0).age, 22); + assertEquals(people.get(0).age, 21); - assertEquals(people.get(1).name, "Nina"); + assertEquals(people.get(1).name, "Waverly"); assertEquals(people.get(1).id, 2); - assertEquals(people.get(1).age, 22); + assertEquals(people.get(1).age, 19); } + // + ////// DESERIALIZE + // + @Test public void test_deserialize_string_object() { String input = - "{\"name\":\"Aidan\",\"_id\":2,\"age\":22," - + "\"spouse\":{\"name\":\"Nina\",\"_id\":6,\"age\":22}}"; + "{\"name\":\"Aidan\",\"_id\":2,\"age\":21," + + "\"spouse\":{\"name\":\"Waverly\",\"_id\":6,\"age\":19}}"; Person object = Ason.deserialize(input, Person.class); assertNotNull(object); } @@ -209,7 +192,8 @@ public void test_deserialize_string_object() { @Test public void test_deserialize_string_array() { String input = - "[{\"name\":\"Aidan\",\"_id\":1,\"age\":22}," + "{\"name\":\"Nina\",\"_id\":2,\"age\":22}]"; + "[{\"name\":\"Aidan\",\"_id\":1,\"age\":21}," + + "{\"name\":\"Waverly\",\"_id\":2,\"age\":19}]"; Person[] object = Ason.deserialize(input, Person[].class); assertEquals(object.length, 2); } @@ -217,29 +201,30 @@ public void test_deserialize_string_array() { @Test public void test_deserialize_string_list() { String input = - "[{\"name\":\"Aidan\",\"_id\":1,\"age\":22}," + "{\"name\":\"Nina\",\"_id\":2,\"age\":22}]"; + "[{\"name\":\"Aidan\",\"_id\":1,\"age\":21}," + + "{\"name\":\"Waverly\",\"_id\":2,\"age\":19}]"; List object = Ason.deserializeList(input, Person.class); assertEquals(object.size(), 2); } @Test public void test_get_object_deserialize() { - String input = "{\"person\":{\"name\":\"Aidan\",\"_id\":1,\"age\":22}}"; + String input = "{\"person\":{\"name\":\"Aidan\",\"_id\":1,\"age\":21}}"; Ason ason = new Ason(input); Person person = ason.get("person", Person.class); assertEquals(person.name, "Aidan"); assertEquals(person.id, 1); - assertEquals(person.age, 22); + assertEquals(person.age, 21); } @Test public void test_get_array_deserialize() { - String input = "[{\"name\":\"Aidan\",\"_id\":1,\"age\":22}]"; + String input = "[{\"name\":\"Aidan\",\"_id\":1,\"age\":21}]"; AsonArray json = new AsonArray<>(input); Person person = json.get(0, Person.class); assertEquals(person.name, "Aidan"); assertEquals(person.id, 1); - assertEquals(person.age, 22); + assertEquals(person.age, 21); } @Test @@ -280,9 +265,13 @@ public void test_serialize_deserialize_null() { assertNull(Ason.serializeList(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void test_serialize_primitive() { - Ason.serialize(1); + try { + Ason.serialize(1); + assertFalse("No exception thrown when serializing primitive!", false); + } catch (IllegalArgumentException ignored) { + } } @Test @@ -312,7 +301,7 @@ public void test_serialize_ason_object_array() { @Test public void test_serialize_array_list_wrong_method() { try { - Ason.serialize(new int[] {1, 2, 3, 4}); + Ason.serialize(new int[]{1, 2, 3, 4}); assertFalse("No exception thrown when using serialize() on array!", false); } catch (IllegalArgumentException ignored) { } @@ -331,19 +320,27 @@ public void test_serialize_array_list_wrong_method() { @Test public void test_serialize_empty_array() { - AsonArray array = Ason.serializeArray(new int[] {}); + AsonArray array = Ason.serializeArray(new int[]{}); assertTrue(array.isEmpty()); } - @Test(expected = RuntimeException.class) + @Test public void test_serialize_inaccessible_field() throws Exception { Field hi = SimpleTestDataOne.class.getDeclaredField("hi"); - AsonSerializer.get().serializeField(hi, new SimpleTestDataTwo()); + try { + AsonSerializer.get().serializeField(hi, new SimpleTestDataTwo()); + assertFalse("No exception thrown when trying to serialize inaccessible field!", false); + } catch (RuntimeException ignored) { + } } - @Test(expected = IllegalArgumentException.class) + @Test public void test_deserialize_primitive_cls() { - Ason.deserialize("{\"hi\":\"hello\"}", Integer.class); + try { + Ason.deserialize("{\"hi\":\"hello\"}", Integer.class); + assertFalse("No exception thrown when passing primitive class to deserialize()!", false); + } catch (IllegalArgumentException ignored) { + } } @Test @@ -388,16 +385,24 @@ public void test_deserialize_null_json() { assertNull(one); } - @Test(expected = IllegalStateException.class) + @Test public void test_deserialize_wrong_object_target() { Ason ason = new Ason("{\"obj\":{\"hi\":\"hello\"}}"); - ason.get("obj.hi", SimpleTestDataOne.class); + try { + ason.get("obj.hi", SimpleTestDataOne.class); + assertFalse("No exception thrown for wrong get() cast.", false); + } catch (IllegalStateException ignored) { + } } - @Test(expected = IllegalStateException.class) + @Test public void test_deserialize_wrong_array_target() { Ason ason = new Ason("{\"obj\":[\"hi\",\"hello\"]}"); - ason.get("obj", SimpleTestDataOne[].class); + try { + ason.get("obj", SimpleTestDataOne[].class); + assertFalse("No exception thrown for wrong get() cast.", false); + } catch (IllegalStateException ignored) { + } } @Test @@ -440,16 +445,26 @@ public void test_auto_deserialize_list() { assertEquals(4, list.get(3).intValue()); } - @Test(expected = IllegalStateException.class) + @Test public void test_auto_deserialize_list_wrong_method() { Ason ason = new Ason().put("array", 1, 2, 3, 4); - ason.get("array", List.class); + try { + ason.get("array", List.class); + assertFalse("Exception not thrown for using the wrong " + "list get() method.", false); + } catch (IllegalStateException ignored) { + } } - @Test(expected = IllegalStateException.class) + @Test public void test_get_list_on_object() { Ason ason = new Ason().put("value", 1); - ason.getList("value", Integer.class); + try { + ason.getList("value", Integer.class); + assertFalse( + "No exception thrown when using getList() for a " + "key that represents a non-array!", + false); + } catch (IllegalStateException ignored) { + } } @Test @@ -462,7 +477,7 @@ public void test_get_list_null() { @Test public void test_issue10_serialize() { Issue10Example data = new Issue10Example(); - data.item = new Object[] {1, 2, 3, 4}; + data.item = new Object[]{1, 2, 3, 4}; Ason ason = Ason.serialize(data); AsonArray array = ason.get("item"); @@ -478,17 +493,25 @@ public void test_issue10_deserialize() { Ason ason = new Ason("{\"item\": [1, 2, 3, 4]}"); Issue10Example result = Ason.deserialize(ason, Issue10Example.class); Object[] array = (Object[]) result.item; - assertTrue(Arrays.equals(new Integer[] {1, 2, 3, 4}, array)); + assertTrue(Arrays.equals(new Integer[]{1, 2, 3, 4}, array)); } - @Test(expected = IllegalArgumentException.class) + @Test public void test_deserialize_array_on_non_array() { - AsonSerializer.get().deserializeArray(new AsonArray(), Integer.class); + try { + AsonSerializer.get().deserializeArray(new AsonArray(), Integer.class); + assertFalse("No exception thrown!", false); + } catch (IllegalArgumentException ignored) { + } } - @Test(expected = IllegalArgumentException.class) + @Test public void test_deserialize_array_on_list() { - AsonSerializer.get().deserializeArray(new AsonArray(), List.class); + try { + AsonSerializer.get().deserializeArray(new AsonArray(), List.class); + assertFalse("No exception thrown!", false); + } catch (IllegalArgumentException ignored) { + } } @Test @@ -511,8 +534,8 @@ public void test_deserialize_all_nulls_to_primitive() { @Test public void test_deserialize_array_of_arrays() { - Integer[] one = new Integer[] {1, 2, 3, 4}; - Integer[] two = new Integer[] {5, 6, 7, 8}; + Integer[] one = new Integer[]{1, 2, 3, 4}; + Integer[] two = new Integer[]{5, 6, 7, 8}; AsonArray jsonArray = new AsonArray().add(one, two); Integer[][] matrix = AsonSerializer.get().deserializeArray(jsonArray, Integer[][].class); assertNotNull(matrix); @@ -552,7 +575,6 @@ public void test_deserialize_array_of_lists() { assertEquals(8, two.get(3).intValue()); } - @SuppressWarnings("unchecked") @Test public void test_deserialize_array_of_empty_lists() { List one = new ArrayList<>(0); @@ -575,18 +597,6 @@ public void test_deserialize_array_of_null_lists() { assertNull(result[1]); } - @Test - public void test_recursive_deserialize() { - Ason ason = - new Ason( - "{\"name\":\"Aidan\",\"power\":\"Flight\",\"_id\":2,\"age\":22,\"spouse\":{\"name\":\"Nina\",\"_id\":6,\"age\":22,\"spouse\":null}}"); - Superhero person = ason.deserialize(Superhero.class, true); - assertEquals(person.name, "Aidan"); - assertEquals(person.id, 2); - assertEquals(person.age, 22); - assertEquals(person.power, "Flight"); - } - @SuppressWarnings("unused") static class Person { @@ -596,9 +606,11 @@ static class Person { String name; int age; Person spouse; - @AsonIgnore String gibberish = "Hello, world!"; + @AsonIgnore + String gibberish = "Hello, world!"; - Person() {} + public Person() { + } Person(int id, String name, int age) { this.id = id; @@ -618,7 +630,8 @@ static class Person2 { Person2[] family; - Person2() {} + Person2() { + } Person2(int id) { this(); @@ -642,27 +655,4 @@ static class Person3 { this.id = id; } } - - @SuppressWarnings("unused") - private static class Superhero extends Person { - - String power; - - Superhero() {} - - Superhero(int id, String name, int age, String power) { - super(id, name, age); - this.power = power; - } - } - - @SuppressWarnings("unused") - private static class EmptyPerson extends Person { - - EmptyPerson() {} - - public EmptyPerson(int id, String name, int age) { - super(id, name, age); - } - } } diff --git a/src/test/java/com/afollestad/ason/AsonTest.java b/src/test/java/com/afollestad/ason/AsonTest.java index 0eb1777..b09a4d5 100644 --- a/src/test/java/com/afollestad/ason/AsonTest.java +++ b/src/test/java/com/afollestad/ason/AsonTest.java @@ -16,9 +16,13 @@ public class AsonTest { - @Test(expected = InvalidJsonException.class) + @Test public void invalid_json_test() { - new Ason("Hello, world!"); + try { + new Ason("Hello, world!"); + assertFalse("No exception thrown for invalid JSON!", false); + } catch (InvalidJsonException ignored) { + } } @Test @@ -74,7 +78,7 @@ public void builder_test() { .put("_id", 3) .put("name", "Aidan") .put("age", 21) - .put("array", (Object) new int[] {1, 2, 3, 4}) + .put("array", (Object) new int[]{1, 2, 3, 4}) .put("list", list); String output = "{\"array\":[1,2,3,4],\"name\":\"Aidan\"," + "\"_id\":3,\"list\":[1,2],\"age\":21}"; diff --git a/src/test/java/com/afollestad/ason/Issue10Example.java b/src/test/java/com/afollestad/ason/Issue10Example.java index 31e399b..dfdabbd 100644 --- a/src/test/java/com/afollestad/ason/Issue10Example.java +++ b/src/test/java/com/afollestad/ason/Issue10Example.java @@ -1,6 +1,8 @@ package com.afollestad.ason; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ class Issue10Example { Object item; diff --git a/src/test/java/com/afollestad/ason/PerfTest.java b/src/test/java/com/afollestad/ason/PerfTest.java index f51e524..7d2e3b2 100644 --- a/src/test/java/com/afollestad/ason/PerfTest.java +++ b/src/test/java/com/afollestad/ason/PerfTest.java @@ -8,7 +8,9 @@ import java.util.Map; import java.util.TreeMap; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ public class PerfTest { private static Gson gson; @@ -73,7 +75,8 @@ private static void asonTest(int sampleSize) { } private static void gsonTest(int sampleSize) { - final Type arrayType = new TypeToken() {}.getType(); + final Type arrayType = new TypeToken() { + }.getType(); long start = System.currentTimeMillis(); for (int i = 0; i <= sampleSize; i++) { diff --git a/src/test/java/com/afollestad/ason/Person.java b/src/test/java/com/afollestad/ason/Person.java index 0ecd4f6..4683232 100644 --- a/src/test/java/com/afollestad/ason/Person.java +++ b/src/test/java/com/afollestad/ason/Person.java @@ -3,7 +3,9 @@ import java.util.ArrayList; import java.util.List; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ class Person { int id; @@ -14,8 +16,9 @@ class Person { Person() { props = - new String[] { - "Hi", "Hey", "Hello", "What is up?", "How is it going?", "Yo", "Hello, world!", "Goodbye" + new String[]{ + "Hi", "Hey", "Hello", "What is up?", "How is it going?", "Yo", "Hello, world!", + "Goodbye" }; relationshipList = new ArrayList<>(); } diff --git a/src/test/java/com/afollestad/ason/Relationship.java b/src/test/java/com/afollestad/ason/Relationship.java index a42807a..91719d1 100644 --- a/src/test/java/com/afollestad/ason/Relationship.java +++ b/src/test/java/com/afollestad/ason/Relationship.java @@ -1,13 +1,16 @@ package com.afollestad.ason; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ class Relationship { int id; String name; String relationship; - Relationship() {} + Relationship() { + } Relationship(int id, String name, String relationship) { this(); diff --git a/src/test/java/com/afollestad/ason/SimpleTestDataOne.java b/src/test/java/com/afollestad/ason/SimpleTestDataOne.java index 59bb8a9..35859e7 100644 --- a/src/test/java/com/afollestad/ason/SimpleTestDataOne.java +++ b/src/test/java/com/afollestad/ason/SimpleTestDataOne.java @@ -1,6 +1,8 @@ package com.afollestad.ason; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ class SimpleTestDataOne { String hi = "hello"; diff --git a/src/test/java/com/afollestad/ason/SimpleTestDataTwo.java b/src/test/java/com/afollestad/ason/SimpleTestDataTwo.java index 9a92e49..8e526ea 100644 --- a/src/test/java/com/afollestad/ason/SimpleTestDataTwo.java +++ b/src/test/java/com/afollestad/ason/SimpleTestDataTwo.java @@ -1,4 +1,8 @@ package com.afollestad.ason; -/** @author Aidan Follestad (afollestad) */ -class SimpleTestDataTwo {} +/** + * @author Aidan Follestad (afollestad) + */ +class SimpleTestDataTwo { + +} diff --git a/src/test/java/com/afollestad/ason/UtilTest.java b/src/test/java/com/afollestad/ason/UtilTest.java index e90f727..bbc8192 100644 --- a/src/test/java/com/afollestad/ason/UtilTest.java +++ b/src/test/java/com/afollestad/ason/UtilTest.java @@ -20,20 +20,27 @@ import org.json.JSONObject; import org.junit.Test; -/** @author Aidan Follestad (afollestad) */ +/** + * @author Aidan Follestad (afollestad) + */ @SuppressWarnings("unused") public class UtilTest { - @AsonIgnore Field ignoreYes1; + @AsonIgnore + Field ignoreYes1; Field $jacocoData; Field ignoreNo2; @SuppressWarnings({"FieldCanBeLocal", "unused", "MismatchedQueryAndUpdateOfCollection"}) private List listField; - @Test(expected = IllegalStateException.class) + @Test public void test_ctor() { - new Util(); + try { + new Util(); + assertFalse("Util class shouldn't be constructed!", false); + } catch (IllegalStateException ignored) { + } } @Test @@ -79,17 +86,25 @@ public void test_is_json_array_false() { assertFalse(isJsonArray(" abc")); } - @Test(expected = IllegalStateException.class) + @Test public void test_no_default_ctor() { - getDefaultConstructor(NoDefaultCtorClass.class); + try { + getDefaultConstructor(NoDefaultCtorClass.class); + assertFalse("No exception thrown for no default constructor!", false); + } catch (IllegalStateException ignored) { + } } - @Test(expected = RuntimeException.class) + @Test public void test_cant_access_field() throws Exception { DefaultCtorClass instance = (DefaultCtorClass) getDefaultConstructor(DefaultCtorClass.class).newInstance(); Field field = DefaultCtorClass.class.getDeclaredField("hiddenField"); - setFieldValue(field, instance, "Test"); + try { + setFieldValue(field, instance, "Test"); + assertFalse("No exception was thrown for accessing inaccessible field!", false); + } catch (RuntimeException ignored) { + } } @Test @@ -101,11 +116,18 @@ public void test_is_null() { assertFalse(isNull(new AsonArray<>())); } - @Test(expected = Throwable.class) + @Test public void test_class_cache_new_instance() { ClassCacheEntry cacheEntry = - new ClassCacheEntry<>(DefaultCtorErrorClass.class, false); - cacheEntry.newInstance(); + new ClassCacheEntry<>(DefaultCtorErrorClass.class); + try { + cacheEntry.newInstance(); + assertFalse( + "No exception was thrown when constructing a " + + "class which throws an error on purpose!", + false); + } catch (Throwable ignored) { + } } @Test @@ -135,14 +157,16 @@ static class DefaultCtorClass { private String hiddenField; @SuppressWarnings("unused") - public DefaultCtorClass() {} + public DefaultCtorClass() { + } } @SuppressWarnings("unused") static class NoDefaultCtorClass { @SuppressWarnings("unused") - public NoDefaultCtorClass(String name) {} + public NoDefaultCtorClass(String name) { + } } @SuppressWarnings("unused")