* Start gradle root
* Clean up test API ambiguities
These don't compile in gradle anymore and the team[] warns
* Exclude .gradle dirs in git
* Set up moshi module
* Set up moshi-adapters
* Add repositories to subprojects
* Set target/source compatibility
* Set up examples
* Fix location of reflect/test dir
* Set up moshi-kotlin
* Set up code gen
* Opportunistic update code gen deps
* Fix up with code gen
* Set up kotlin tests
* Update snapshots
* Update travis build
* Configure checkstyle
* Cache gradle
* Finish fixing up checkstyle
* Now disable checkstyle until we can fix them all :|
* Update contributing
* Fix tests in codegen
* Remove unnecessary annotation
* Remove maven stuff!
* Suppress warning
* Remove jcenter
* Consolidate dependencies
* Revert "Clean up test API ambiguities"
This reverts commit 3ead69b844b5d7f66134b721e95581f5df1cccd6.
* Fix incap dep
* Opportunistically fix some small kotlinpoet deprecations
* Automatically apply the stdlib to all kotlin projects
* Opportunistic move to opt-in and remove unnecessary annotations
The kotlin maven plugin didn't handle these well in the IDE, gradle does
* Fix Type doc warning
* Fix okio version
* Fix dokka support
* Fix copypasta
* Use new snapshot
* Kotlin 1.4.0
* Expose getStrings() option on JsonReader.Options
Resolves#1173
* Fix clone
Co-authored-by: Jake Wharton <github@jakewharton.com>
* Add mutation check
* Use set and make it unmodifiable
* Back to list
* strings()
* No clone()
Co-authored-by: Jake Wharton <github@jakewharton.com>
This makes application build with Moshi to keep unwanted Kotlin Metadata that have a huge impact on APK size.
After discussion with R8 team, there's currently no solution to avoid this other than using the trick in this PR.
Fixes https://github.com/square/moshi/issues/1115
A new user of Moshi might try to make a class like
data class Response (
val users: ArrayList<User>
)
Then when trying to create a JsonAdapter for it, they get an unhelpful error
message like
Platform class java.util.ArrayList in java.util.ArrayList<java.lang.String>
requires explicit JsonAdapter to be registered
which doesn't explain what they should do to fix the problem. In fact what it
hints towards is that the user should implement a JsonAdapter for ArrayList,
when really they just need to change the type to List!
Now the error looks like
No JsonAdapter for java.util.ArrayList<java.lang.String>, you should use
List instead of ArrayList (Moshi only supports the collection interfaces
by default).
* Extract target constructor signature into TargetConstructor.kt
We'll need this to know what the runtime types are for proguard rules
* Add ProguardConfig
* Wire in proguard config
* Write proguard configs out with adapters
* Add full tests
* Now remove the rules!
* Ignore on inline classes for now
* Pass adapter constructor params correctly
Reported by a Googler - We currently gate the lookup of the class on the presence of `Metadata`. However, `Metadata` might be justifiably stripped by Proguard/R8, even though `DefaultConstructorMarker` might still be present. This means Moshi's defaults invocation is likely broken on (at least) R8 builds without this.
Workaround until next release is to keep Metadata annotations
* Fix broken test
This test suite doesn't run on CI builds but fails locally since the method was moved
* Add multiple constructors test case
* Implement TypeName.asTypeBlock()
* Make DEFAULT_CONSTRUCTOR_MARKER public
* Look up constructor via getDeclaredConstructor with exact param types
Resolves#975
* Remove dead code
The attempted fix replaced a warning with a crash. I believe that a
warning is a better developer experience than a crash.
This reverts commit c0639316b1.
* Port Gson Types recursion fix for subtypeOf/supertypeOf
From a300148003
First step in resolving #338
* Port Gson Type resolve() recursion fix for type variables
From https://github.com/google/gson/pull/1128Resolves#338
* Capture adapter to make checkstyle happy
* Move RecursiveTypesResolveTest out of internal package
* Use moshi convention for tests
* 2 is not 1
Unlike `value(BufferedSource)`, this retains the push-based nature of JsonWriter and allows layering other sinks (such as a base64-encoding Sink for binary data). Since `value(BufferedSource)` is trivially replaced by reading the source into the value sink, it is deprecated.
* Report json name in code gen if different from property name
Resolves#800
* Unify required property name error message
* Report json name in kotlinjsonadapter, match code gen
* Upper case JSON
Co-Authored-By: Jake Wharton <jakew@google.com>
* Upper case JSON
Co-Authored-By: Jake Wharton <jakew@google.com>
* Don't keep constants
* Inline json name - property name comparison to util methods
* Remove unnecessary constructor keyword
* Consolidate non-null/missing property tests to parameterized suite
* Add custom json name tests for nonNull property checks
* Rename test to make maven happy
Maven won't run the test unless it ends with `Test` or `TestCase`
It's a programmer error to omit this, but vararg declaration allows you to. This checks that.
We could improve it to ensure matching lengths or bounds, but this is a good start.
* Don't try to access unsafe APIs on android 29+
Resolves#872. Not sure if we want to try caching some of these lookups
* Checkstyle
* Use correct inner class naming
Co-Authored-By: Jake Wharton <jakew@google.com>
* Name variable ignored
* Cache android check
* Differentiate local naming from properties with constructor defaults
* Remove constructor invocation and mask creation methods
We're inlining all this
* Add explanatory comment for why we use the default primitive value
* Inline mask generation and constructor invocation to generated adapters
* Remove unused argument
Co-Authored-By: Jake Wharton <jakew@google.com>
* Compute masks directly during code gen
* Opportunistic: remove extraneous double space from control flow
* Just mask and invert directly
* Don't re-wrap nullsafe/nonnull adapters if they are already one
nullSafe() is often called defensively, which can lead to a lot of layers of wrapping and checking. This avoids that overhead where possible.
* Add tests
* Add Util#invokeDefaultConstructor
* Add defaultPrimitiveValue
This will be used to initialize required properties for later invocation of the default constructor
* Move isTransient into PropertyGenerator
We will need this in order to know how to invoke constructors even if they have transient parameters
* Add notion of hasLocalIsPresentName to PropertyGenerator
* Switch to using invokeDefaultConstructor for any default property types
* Add code gen versions of default constructor test
* Fix mismatched names
* Use Arrays.copyOf
* Unwrap InvocationTargetException
* Use name allocator
* Rename createMask to createDefaultValuesParametersMask, use it directly
* Opportunistically clean up result variable holder
Only needs to be made if we have non-parameter instances, otherwise we can just return directly
* Fix mask name
* Remove unnecessary mod
* Switch to local lazily-initialized constructor reference
Not working because of some issue in kotlinpoet I don't understand
* Fix named usage
* Clean up debugging dots
* Add proguard/R8 rule for keeping defaults constructor in targets
* Make constructor lookup property private
* Add another defensive dot
* Rework invokeDefaultConstructor to accept vararg args
A little more idiomatic
* Update proguard rules
* Start MoshiKotlinExtensions
* Add Moshi.Builder.add() with reified typeOf
* Use non-shadowing name for addAdapter
* Implement KType.toType()
.javaType isn't implemented
* Don't re-wrap wrapped adapters
* Use new adapter functions in tests to smoke test
* Don't enable uses experimental in kotlin-reflect, only the test
* Use internal leniency API
* Use toType in addAdapter too
* Update error message in test
* Extract generatedJsonAdapterName to public API for other generators/consumers
* Fix kapt location in tests
* Add IDE-generated dependency-reduced-pom.xml to gitignore
This always bites me
* Add generator property to JsonClass and skip in processor
* Opportunistically fix formatting for generateAdapter doc
* Extract NullSafeJsonAdapter for delegate testing
* Add custom adapter tests
* Allow no-moshi constructors for generated adapters
* Fix rebase issue
* Use something other than nullSafe() for lenient check
This no longer propagates lenient
* Add missing copyrights
* Add top-level class note
* Add note about working against Moshi's generated signature
* Add missing bit to "requirements for"
* Note kotlin requirement relaxed in custom generators
* Style