Commit graph

498 commits

Author SHA1 Message Date
Jesse Wilson
d045947ea7
Split the MoshiKotlinCodeGenProcessor into multiple types. (#462)
Move more behavior into the types: Adapter and Property now have many
instance methods and are now mutable value classes rather than immutable
data classes.

This changes how some of the bookkeeping code works. Previously there were
some pretty tricky types: maps with pairs as keys, indexed and non-indexed
lists of properties. With this change more of the logic operates directly
on the properties.
2018-03-24 20:53:08 -04:00
Zac Sweers
96e074d030 Kotlin Code Gen module (#435)
* Add kotlin code gen modules

* Update kotlin to 1.2

* Add a serializable dummy class

* Try using kapt configuration from kotlin-examples repo

Still no luck!

* Use proper allocated name for assignment too

* Use selectName() API

* Clean up constructor parameter annotations & plumbing for qualifiers

* Updates poms and kotlin code gen processor to support tests.

* Ignore kotlin code gen tests for now

None of these are data classes tests right now, which is the only thing this supports right now

* Replace $ with _ in class names for consistency

* Shortcut Array types to arrayOf

* Add DataClassTest

* Try generated option first, fall back to maven after

* More idiomatic handling

* Only use nonnullable types for adapter properties

* Code dump of kotshi tests

* Comment out specifics to get compiling

* Generics support!

* Fix double primitive default

* Pick up temporary snapshot for Any fix

* Invariance should just be null

* Better handling of nullably-bound variance

* Just assume the first jvm constructor for now as jvmMethodSig is flaky

* Specify types param if needed

* Don't do lazy delegation

* Clean up nullable typevariablename boundaries

* Add type variables to extension function on companion object

* Use properties instead of allocated names for more robustness

Since we're already on a snapshot

* If there are no type variables, make it null for simpler handling

* Fix generics and Type[] handling

* Fix unnecessary as casts on primitive defaults

* Reference spec directly for possible bangs

* Use nullSafe() adapters for anything nullable or with default values

* Use object type in makeType()

Types.java cares

* Make TestPrimitiveDefaultValues work

* Re-enable TestClassWithJavaKeyword

* Ignore remaining tests that are pending decisions or JsonQualifier support

* Remove customnames test as we're just going to stick with simple @Json

* Add toString() implementations

* Reenable default values testing, adapt to kotlin lang support

* Remove primitive adapters bits since we're not using it

* Clean up a bunch of leftover comments

* Switch to only nullable handling, report missing properties

This makes all nullable handling for local properties the same, and removes defaults for primitives in the process. It simplifies the handling a lot, and leans on kotlin language features to take care of null handling (null checking and then throwing the lazily evaluated list of missing properties).

One minor change from what kotshi does - this reports the serialized name in the missing properties, not the property name. We could look at supporting this though if we want.

* Implement JsonQualifier support

* Use Kapt for AutoService/processor declaration

* Checkstyle

* Remove unused primite type checks

* Add test verifying mutable and immutable collections work

* Fix test name

* Standardize isRequired checks

* Add more nullability and mutability tests

* Kotlinpoet 0.7.0 final

* Switch to new vararg overload for annotation class adapter()

* Make suffix just JsonAdapter without underscore

* Switch to just a regular constructor for MoshiSerializableFactory

* Remove constructor caching

* Remove unnecessary framework class checks

* Nix unnecessary superclass lookups, inline constructor lookup

* Nix null token check in reads

* Nix null check in writes, do !! on first value use

* Nix null checks in favor of serializeNulls

* Inline null checks and fail eagerly

* Fix double _Adapter

* First pass at simplifying adapter names

* Inline names to options property, life into class and rm companion

* Differentiate between absent and null, use nullSafe() as needed

* Group together compile and test dependencies

* Remove incorrect comment

* Revert formatting

* Set, not mutable set

* Collapse else-if nesting to one when

* Cleaner formatting test code

* Collapse more to locals

* Collapse more

* Return a nonnullable type in fromJson

* Remove redundant out variance

* Use KClass where appropriate

* End comment in period

* Remove redundant comment

* Throw on unrecognized type in simplified name

* Use illegalargumentexception instead

* Emit a nullcheck at the beginning of toJson instead

* Remove extra newline

* Simplify processing to be less abusive

* Skip using asClassName() when possible

* Use addComment()

* Switch to declared constructors

Technically more correct since we're defining these

* Unmodifiable set

* return adapter(type, annotationTypes[0])

* Slight optimization - check if the type is parameterized first

If the type is a parameterized type, then we know they'll have the two-arg constructor. This way we don't always try and fail the single arg constructor on parameterized types

* Add test for type aliases, optimize to reuse adapters if possible

This is a tiny optimization to make type aliases (which did already work) reuse adapter properties if they already exist for the backing type. What this means is that if you have:

typealias Foo = String

and properties
foo: Foo
bar: String

you'll only get one adapter property field for String, and both will use it

* Use string templating where possible

* Remove all the kotshi tests
2018-03-11 21:17:55 -04:00
Eric Cochran
e6c2ebedde Disallow null annotation set in adapter lookup. (#460) 2018-03-10 06:42:07 -05:00
Ekalips
ce879634cc Add single quotes to variable names (#452) (#458) 2018-02-27 09:12:43 -05:00
Jake Wharton
dfc075515d
Merge pull request #451 from square/jwilson.0225.https_links
Use HTTPS links in documentation where possible.
2018-02-25 22:20:02 -05:00
Jesse Wilson
caedfea74b Use HTTPS links in documentation where possible. 2018-02-25 22:09:56 -05:00
Eric Cochran
8e28dd4ad7 Fail earlier for some incorrect owner types. (#450) 2018-02-24 04:46:42 -05:00
Eric Cochran
ed1ea5a755 JsonAdapter.fromJson(String) must fully consume. (#441)
* JsonAdapter.fromJson(String) must fully consume.

* Replace field with method.
2018-02-21 20:15:38 -05:00
Eric Cochran
aede26d5e1 Clarify negation in condition. (#444) 2018-02-18 06:56:29 -05:00
Eric Cochran
3b89cf1fcb Fix ClassJsonAdapter to handle ParameterizedTypes. (#422) 2018-02-17 22:56:05 -05:00
Eric Cochran
834a401122 Crash earlier for property type conflicts. (#377) 2018-02-17 22:51:02 -05:00
Robert Stoll
a00860ee1d mention that KotlinJsonAdapterFactory validates (#439)
See #438 for the use case. The documentation was not accurate enough IMO. Thus, mention that KotlinJsonAdapterFactory is required for validation.
2018-02-17 22:17:42 -05:00
Jake Wharton
a6d31ba0b4
Merge pull request #440 from square/jakew/tiny-tweak/2018-02-13
Reduce visual complexity of branching.
2018-02-13 16:35:23 -05:00
Jake Wharton
bc7d849362 Reduce visual complexity of branching. 2018-02-13 15:04:34 -05:00
Jake Wharton
b131d3bba0
Merge pull request #434 from square/jwilson.0207.modulename
Move modules into their own packages.
2018-02-07 09:25:18 -05:00
Jesse Wilson
5ad9d31bd8 Move modules into their own packages.
This sets the Automatic-Module-Name for moshi, moshi-adapters, and moshi-kotlin.
It moves moshi-adapters into its own .adapters package and forwards the existing
adapter. It moves the moshi-kotlin into its own .kotlin package and forwards the
existing adapter.

I'm not certain this is necessary or sufficient, but I think it's the right idea
for JPMS compatibility.
2018-02-07 04:41:06 -05:00
Eric Cochran
d26b2a151f Fix error message for invalid toJson signature. (#431)
void toJson(JsonWriter, JsonAdapter) does not make sense. This looks like my copy-paste error.
2018-02-03 23:50:22 -05:00
Eric Cochran
5b194964a9 Disallow irregular Kotlin classes. (#424) 2018-01-10 22:07:13 -05:00
Eric Cochran
9deeb62e77 Add permalink to ISO8601Utils.java. (#425)
This file was removed from master a few months ago.
2018-01-10 21:57:00 -05:00
Eric Cochran
dba2f05b13 Improve error message for local classes. (#423) 2018-01-10 21:56:37 -05:00
Jesse Wilson
5d12c22f44
ByteStrings example. (#419)
Closes: https://github.com/square/moshi/issues/31
2018-01-07 23:04:25 -05:00
Jesse Wilson
7205690bf5
Add a standard example for JSON adapter factories. (#420)
Closes: https://github.com/square/moshi/issues/136
2018-01-07 23:04:07 -05:00
Jesse Wilson
359244e996
Fix JsonValueReader to support up to 255 levels of nesting. (#417)
Follow up to https://github.com/square/moshi/pull/349
2018-01-07 14:55:02 -05:00
Eric Cochran
d2ef4b5a61 Clarify error for non-null Kotlin properties. (#376)
Instead of throwing an InvocationTargetException.
2018-01-07 14:07:56 -05:00
Eric Cochran
a210d89a55 Don't handle WildcardTypes in ClassJsonAdapter. (#406) 2018-01-07 14:05:49 -05:00
Jesse Wilson
0a6e836762
Support up to 255 levels of nesting. (#349)
Closes: https://github.com/square/moshi/issues/348
2018-01-07 12:17:00 -05:00
Jake Wharton
8cde0e5d72
Merge pull request #413 from Egorand/egorand/raw-string
Use raw string literals to improve test data readability
2017-12-15 12:53:35 -05:00
Egor Andreevici
07f5d708dd Use raw string literals to improve test data readability 2017-12-15 14:01:45 +02:00
Eric Cochran
f53a77d311
Fix doc reference to Token. (#403)
JsonReader.Token is less redundant than Gson's JsonReader.JsonToken.
2017-12-01 12:07:26 -08:00
Eric Cochran
a8b1550e7e
Make selectString consistent across JsonReaders. (#399)
Make JsonValueReader.selectString return -1 for non-strings instead of throwing.
2017-11-27 15:33:03 -08:00
Jake Wharton
20ffd22110
Merge pull request #398 from sullis/kotlin-1.1.60
kotlin 1.1.60
2017-11-24 16:39:28 -05:00
Sean Sullivan
b06f65d2e9 kotlin 1.1.60 2017-11-24 16:27:37 -05:00
Eric Cochran
f922371fa8 Let JsonValueReader.nextString read numbers. (#390)
* Let JsonValueReader.nextString read numbers.

This adds parity with JsonUtf8Reader and lets big number literals in JSON be read in as strings in Java.

* Remove trailing 0 in float literal.
2017-11-24 07:23:12 -05:00
Jesse Wilson
03323ae998
Merge pull request #392 from square/eric.primitives
Add error message for accidental primitive usage.
2017-11-21 19:06:13 -05:00
Eric Cochran
2b7e5a3453 Add error message for accidental primitive usage.
Also, add a test for the requirement.
2017-11-11 18:37:04 -08:00
Eric Cochran
b7a91e0557 Update to Error Prone 2.1.2. (#384) 2017-11-06 11:49:22 -08:00
Eric Cochran
fd5c5ee2df
Fix a typo in the changelog. (#386) 2017-11-05 13:57:59 -08:00
Jake Wharton
d6742be404
Merge pull request #383 from square/eric.20171104.checkreturnvalue
Add @CheckReturnValue to appropriate public APIs.
2017-11-05 08:51:57 -08:00
Jesse Wilson
5812c994b1
Merge pull request #385 from square/eric.20171105.transient_constructor_error
Clarify error message for transient parameters.
2017-11-05 11:16:54 -05:00
Eric Cochran
b583adac37 Clarify error message for transient parameters.
Otherwise, the error message is misleading: "No property for required constructor $parameter"
2017-11-05 01:06:54 -08:00
Eric Cochran
e643a04ee5 Add @CheckReturnValue to appropriate public APIs. 2017-11-04 21:13:07 -07:00
Jesse Wilson
4ac0d6f5ef
Merge pull request #375 from square/eric.kotlin_readme
Document adding the KotlinJsonAdapterFactory.
2017-10-29 09:11:09 -04:00
Eric Cochran
88ec00bcf4
Document adding the KotlinJsonAdapterFactory.
If you add a custom Kotlin JsonAdapter factory after the KotlinJsonAdapterFactory, you're going to have a bad time.
2017-10-29 05:38:48 +00:00
Jake Wharton
f06b43b2a4
Merge pull request #374 from square/eric.cleanup_33
Update to Kotlin 1.1.51.
2017-10-28 10:13:54 +01:00
Eric Cochran
e0ad48cd97 Update to Kotlin 1.1.51. 2017-10-28 10:07:05 +01:00
Jesse Wilson
8bf298ac14 Merge pull request #360 from square/eric.20171004.delegate-adapters
Allow delegates for intermediates in adapters.
2017-10-04 21:53:12 -04:00
Eric Cochran
4376a50f1f Clarify delegation with qualifiers test. (#359) 2017-10-04 16:49:23 -07:00
Eric Cochran
f847d47daa Remove Types.equal. (#358)
Nobody uses this helper method.
2017-10-04 15:54:17 -07:00
Eric Cochran
de336ef86e Allow delegates for intermediates in adapters. 2017-10-04 15:53:33 -07:00
Jake Wharton
224369155e Merge pull request #355 from square/eric.20170925.proguard
Update ProGuard config for CheckReturnValue.
2017-09-25 15:51:55 -04:00