Commit graph

498 commits

Author SHA1 Message Date
Eric Cochran
84745b0537 Disallow null Type from entering user code.
Otherwise, Moshi.adapter(null) will end up calling into user JsonAdapter factories with a null Type parameter.
Kotlin fails with java.lang.IllegalArgumentException: Parameter specified as non-null is null
That message ends up too far away from the real error.
2018-04-15 21:04:17 -07:00
Jesse Wilson
cc2c818341 Begin to resolve supertype type parameters 2018-04-15 23:21:15 -04:00
Eric Cochran
b860b6da4f
Make error message for dangling names consistent. (#501) 2018-04-15 19:48:32 -07:00
Jesse Wilson
3a2367036c
Merge pull request #505 from square/jwilson.0415.honor_kotlin_supertypes
Support generated adapters for Kotlin superclasses
2018-04-15 15:51:25 -04:00
Jesse Wilson
9401a810f0 Support generated adapters for Kotlin superclasses 2018-04-15 14:37:49 -04:00
Jesse Wilson
8d24d89abf
Model target types, parameters, constructors and properties (#504)
This is intended to make it easier to implement support for subtypes.
2018-04-15 13:46:58 -04:00
Eric Cochran
78091aeb46 Fix JsonUtf8Writer to be strict about names in the wrong place. (#502) 2018-04-15 09:39:04 -04:00
Zac Sweers
941229b6c9 Add apoptions support in KotlinCompilerCall (#499)
* Add apoptions support to KotlinCompilerCall

* Add bad annotated annotation test
2018-04-11 22:30:21 -04:00
Jesse Wilson
f9b758b5bf
Merge pull request #498 from square/jwilson.0410.multiple_types_example
Add an example that decodes multiple formats
2018-04-10 22:20:52 -04:00
Jesse Wilson
c4e4e8582d Add an example that decodes multiple formats 2018-04-10 22:08:31 -04:00
Jesse Wilson
91417d58c6
Merge pull request #496 from square/jwilson.0409.setters
Support properties that don't have a backing field.
2018-04-10 21:15:55 -04:00
Jesse Wilson
d1df4740d5 Support properties that don't have a backing field.
Currently our main loop to gather PropertyGenerators goes over the backing fields.
This needs to change to iterate over the properties themselves. That leads to a lot
of churn. The net result is slightly more compatibility with the reflective adapter.
2018-04-09 00:08:15 -04:00
Jesse Wilson
e80cf48484
Merge pull request #490 from square/jwilson.0407.generate_nonnull
Use JsonAdapter.nonNull() in generated adapters.
2018-04-08 21:05:44 -07:00
Jesse Wilson
cb9c084d30 Use JsonAdapter.nonNull() in generated adapters.
Also extract a type for the delegate key.

Also fix the generator to reject inner classes, abstract classes,
and local classes.
2018-04-08 20:54:50 -04:00
Jesse Wilson
0a49ae3ac8
Merge pull request #491 from square/eric.jsonclass-data
Remove data class limitation from JsonClass doc.
2018-04-08 05:26:37 -07:00
Jesse Wilson
ceef5dc682
Merge pull request #493 from square/eric.never-type-equals
Fix type checks with custom adapters.
2018-04-08 05:26:13 -07:00
Jesse Wilson
e43a173f46
Merge pull request #494 from square/eric.2018-04-07.with-no-annotations
Make "no adapter" error message friendlier.
2018-04-08 04:27:55 -07:00
Eric Cochran
ba1318cc45 Make "no adapter" error message friendlier.
In the very common case, there are no JsonQualifier annotations for the type.
2018-04-08 00:48:38 -07:00
Eric Cochran
fa1f10dc77
Fix type checks with custom adapters.
Moshi.Builder.add(Type, ...) adds a factory that had a broken type equality check.
Closes #128
2018-04-08 00:42:46 -07:00
Eric Cochran
c4a2e7657f
Remove data class limitation from JsonClass doc. 2018-04-07 20:33:22 -07:00
Jesse Wilson
2cc878da81
Merge pull request #489 from jemaystermind/jemaystermind/indent-json
Indent JSON string properly
2018-04-07 05:07:03 -07:00
Jeremy Tecson
bfa14a0d66
Indent JSON string properly 2018-04-07 17:59:02 +08:00
Jesse Wilson
5ecb55ad1e
Merge pull request #488 from square/eric.okio-update
Update to Okio 1.14.0.
2018-04-06 20:20:52 -07:00
Jesse Wilson
73f8774aa8
Merge pull request #487 from square/eric.adapters-readme
Use direct link to adapters snapshots.
2018-04-06 20:20:32 -07:00
Jesse Wilson
b52d63dfbf
Merge pull request #486 from square/eric.integration-reflect
Remove kotlin-reflect dep from integration-test.
2018-04-06 20:19:55 -07:00
Eric Cochran
083210eb40 Add generated code file comment. (#485) 2018-04-06 20:18:43 -07:00
Eric Cochran
14f2dcc357
Update to Okio 1.14.0. 2018-04-06 17:10:33 -07:00
Eric Cochran
e5e4fde1dc
Use direct link to adapters snapshots. 2018-04-06 16:23:51 -07:00
Eric Cochran
7d4a10f521
Remove kotlin-reflect dep from integration-test. 2018-04-06 16:17:26 -07:00
Eric Cochran
dbdf48777c Simplify example code. (#483)
* Simplify example code.

This was copied code from a different example that used the delegate annotations.

* Make brackets consistent.
2018-04-05 11:05:40 -07:00
Jesse Wilson
7cab83a8f2
Merge pull request #482 from square/jwilson.0404.nonNull
JsonAdapter.nonNull() forbids explicit nulls in the JSON body
2018-04-05 06:42:19 -07:00
Jesse Wilson
8dd8645b61
Merge pull request #481 from square/eric.fallback-enum-sample
Add example for custom qualifier with an element.
2018-04-05 06:41:29 -07:00
Jesse Wilson
466f77aabe JsonAdapter.nonNull() forbids explicit nulls in the JSON body
This adapter modifier throws exceptions if an unexpected null is
encountered. This may pair nicely with Kotlin.
2018-04-04 23:08:36 -07:00
Eric Cochran
fbe95fe51e Add example for custom qualifier with an element. 2018-04-04 18:41:15 -07:00
Jesse Wilson
ad69a4f495
Merge pull request #477 from square/eric.util
Hide Types.resolve.
2018-04-04 10:26:14 -07:00
Eric Cochran
a931184edf Hide Types.resolve. 2018-04-03 23:35:32 -07:00
Jesse Wilson
c1b93247e3
Merge pull request #475 from square/eric.resolve-generics
Resolve generic property types in KotlinJsonAdapter.
2018-04-04 01:18:31 -04:00
Jesse Wilson
75f2d5c8dd
Merge pull request #474 from hzsweers/z/newmetadata
Update to kotlin-metadata 1.3.0 and just use mavencentral
2018-04-04 01:16:03 -04:00
Jesse Wilson
42f4f956e0
Merge pull request #473 from square/jwilson.0403.qualifiers_names_transient
Handle qualifiers, names, and transient in generated adapters
2018-04-04 00:42:47 -04:00
Eric Cochran
dc450e6192 Resolve generic property types in KotlinJsonAdapter. 2018-04-03 17:37:38 -07:00
Zac Sweers
5f4c46f402 Update to kotlin-metadata 1.3.0 and just use mavencentral 2018-04-03 13:23:38 -07:00
Jesse Wilson
d555d24d94 Handle qualifiers, names, and transient in generated adapters 2018-04-03 11:00:40 -04:00
Zac Sweers
5c45d1e0d9 Generate @Generated annotation onto adapters when possible (#466)
* Generate `@Generated` annotation onto adapters when possible

Part of #461

This leverages AutoCommon's `GeneratedAnnotations#generatedAnnotation` API to generate a `@Generated` annotation where possible. This keeps with conventions in other code gen tools, and also allows for more fine grained proguard rules for keeping generated adapter names, like so:

```proguard
-keepnames @com.squareup.moshi.<wherever this ends up>.MoshiSerializable class *

# Java < 9
-keepnames @javax.annotation.Generated class **JsonAdapter

#  Java 9+
-keepnames @javax.annotation.processing.Generated class **JsonAdapter
```

Generated annotation looks like this:

```kotlin
@Generated(
        value = ["com.squareup.moshi.MoshiKotlinCodeGenProcessor"],
        comments = "https://github.com/square/moshi"
)
```

This doooooes also replace `elements` in `AdapterGenerator` with a `ProcessingEnv`, but I figured that was less evil than polluting it with both `elements` and plumbing down an `env` separately simultaneously. This does also hit a weird ambiguity case due to `KotlinMetadataUtils`' repeat declaration, so a good reason for removing that in the future. Figured it best to punt on a better final place for this to another time.

* Remove names and brackets

* Add moshi.generated option

* Switch back to element property rather than processingEnv

* Fold the kotlin-codegen-runtime into Moshi itself.

Rename @MoshiSerializable to @JsonClass. Like @Json, I'm anticipating
a future where there are other interesting properties on this annotation.
Perhaps a future feature where Moshi is strict and only adapts types that
have a '@JsonClass' annotation.

Also rename MoshiKotlinCodeGenProcessor to JsonClassCodeGenProcessor. We
may later support other ways of generating code here; perhaps for regular
Java types.

* Generate `@Generated` annotation onto adapters when possible

Part of #461

This leverages AutoCommon's `GeneratedAnnotations#generatedAnnotation` API to generate a `@Generated` annotation where possible. This keeps with conventions in other code gen tools, and also allows for more fine grained proguard rules for keeping generated adapter names, like so:

```proguard
-keepnames @com.squareup.moshi.<wherever this ends up>.MoshiSerializable class *

# Java < 9
-keepnames @javax.annotation.Generated class **JsonAdapter

#  Java 9+
-keepnames @javax.annotation.processing.Generated class **JsonAdapter
```

Generated annotation looks like this:

```kotlin
@Generated(
        value = ["com.squareup.moshi.MoshiKotlinCodeGenProcessor"],
        comments = "https://github.com/square/moshi"
)
```

This doooooes also replace `elements` in `AdapterGenerator` with a `ProcessingEnv`, but I figured that was less evil than polluting it with both `elements` and plumbing down an `env` separately simultaneously. This does also hit a weird ambiguity case due to `KotlinMetadataUtils`' repeat declaration, so a good reason for removing that in the future. Figured it best to punt on a better final place for this to another time.

* Fix rebase conflicts and sync with remote
2018-04-03 03:27:57 -04:00
Jesse Wilson
e0d84e1fee
Merge pull request #472 from square/jwilson.0402.beyond_data_classes
Support non-data classes for generated JsonAdapters
2018-04-02 19:38:19 -04:00
Jesse Wilson
b3d7dfd603 Support non-data classes for generated JsonAdapters
This is towards making the reflection and codegen adapters work the same.
The process is relatively straightforward: try to promote all of the tests
in KotlinCodeGenTest to be passing tests in GeneratedAdaptersTest or
compile failures in CompilerTest
2018-04-02 00:37:17 -04:00
Jesse Wilson
7750d179be
Merge pull request #471 from square/jwilson.0331.kompile_testing
Call the kotlin compiler from within a test case.
2018-04-01 05:50:59 -04:00
Jesse Wilson
0c24bd4846 Call the kotlin compiler from within a test case.
This is a fragile first step.
2018-03-31 00:57:50 -04:00
Jesse Wilson
bb7a1c7a27
Merge pull request #464 from square/jwilson.0324.fold_runtime
Fold the kotlin-codegen-runtime into Moshi itself.
2018-03-28 20:59:58 -04:00
Jesse Wilson
982f9c94f6 Fold the kotlin-codegen-runtime into Moshi itself.
Rename @MoshiSerializable to @JsonClass. Like @Json, I'm anticipating
a future where there are other interesting properties on this annotation.
Perhaps a future feature where Moshi is strict and only adapts types that
have a '@JsonClass' annotation.

Also rename MoshiKotlinCodeGenProcessor to JsonClassCodeGenProcessor. We
may later support other ways of generating code here; perhaps for regular
Java types.
2018-03-28 20:26:20 -04:00
Szymon Kozak
351bc57554 Change compile to implementation in README (#467) 2018-03-27 17:43:46 -07:00