Commit graph

40 commits

Author SHA1 Message Date
Jesse Wilson
31ef245eeb [maven-release-plugin] prepare for next development iteration 2018-05-14 23:00:15 -04:00
Jesse Wilson
bf4d1f8693 [maven-release-plugin] prepare release moshi-parent-1.6.0 2018-05-14 23:00:02 -04:00
Jesse Wilson
0b26628232
Merge pull request #536 from square/jwilson.0514.cast_shade
Shade unreleased KotlinPoet 0.7.0.
2018-05-14 22:52:35 -04:00
Jesse Wilson
b857388796 Shade unreleased KotlinPoet 0.7.0.
That way we won't collide with other annotation processors if they have an
incompatible version.
2018-05-14 22:40:29 -04:00
Jesse Wilson
dd3043722e Generated adapters should use skipName(), not nextName(). 2018-05-14 22:39:33 -04:00
Jesse Wilson
dd84b9f8f8 Change the Kotlin reflection adapter to yield to the codegen adapter 2018-05-14 21:07:46 -04:00
Jesse Wilson
60cb608956 Move Kotlin reflection into a kotlin/reflect directory
The maven coordinates stay the same.
2018-05-14 17:28:28 -04:00
Jesse Wilson
9f69029ef0 Move the Kotlin code generator to the kotlin/ module 2018-05-14 16:29:52 -04:00
Jesse Wilson
13952c5430 Finish migrating tests from the reflective adapter 2018-05-13 21:52:06 -04:00
Jesse Wilson
986cc4c794 [maven-release-plugin] prepare for next development iteration 2018-05-06 21:50:45 -04:00
Jesse Wilson
c2f890879c [maven-release-plugin] prepare release moshi-parent-1.6.0-RC1 2018-05-06 21:50:39 -04:00
Jesse Wilson
c35e3a1550 Fix some tests that have the wrong expected exception message
The message got improved in a conflicting change to these tests being added.
2018-05-04 15:39:55 -04:00
Jesse Wilson
eb24a23568
Merge pull request #511 from square/eric.non-null
Fix error message for assigning to non-null properties.
2018-05-04 15:06:35 -04:00
Jesse Wilson
98c4358615
Merge pull request #519 from square/eric.kotlin-path
Fix path for non-null value message.
2018-05-04 14:31:39 -04:00
Eric Cochran
b848f1cc52 Add JsonReader.skipName. 2018-04-30 18:41:18 -07:00
Eric Cochran
dfaf3405b2 Fix path for non-null value message. 2018-04-30 18:18:34 -07:00
Eric Cochran
51d23b5b33 Fix error message for assigning to non-null properties.
instead of falling down to "Required property 'a' missing at $"
2018-04-24 13:05:22 -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
a931184edf Hide Types.resolve. 2018-04-03 23:35:32 -07:00
Eric Cochran
dc450e6192 Resolve generic property types in KotlinJsonAdapter. 2018-04-03 17:37:38 -07: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
Ekalips
ce879634cc Add single quotes to variable names (#452) (#458) 2018-02-27 09:12:43 -05:00
Eric Cochran
834a401122 Crash earlier for property type conflicts. (#377) 2018-02-17 22:51:02 -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
5b194964a9 Disallow irregular Kotlin classes. (#424) 2018-01-10 22:07:13 -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
Egor Andreevici
07f5d708dd Use raw string literals to improve test data readability 2017-12-15 14:01:45 +02: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
e0ad48cd97 Update to Kotlin 1.1.51. 2017-10-28 10:07:05 +01:00
Eric Cochran
1340ef8935 JsonAdapter.Factory.create rejects the null Type.
This fails already in Types.getRawType, but a compiler error is preferable.
2017-07-24 11:06:22 -07:00
jwilson
d3926a7f86 Add a test to demonstrate the 32-parameter limit 2017-06-10 21:07:01 -04:00
jwilson
798f14bda5 [maven-release-plugin] prepare for next development iteration 2017-05-14 22:20:00 -04:00
jwilson
f42ae45f4c [maven-release-plugin] prepare release moshi-parent-1.5.0 2017-05-14 22:19:55 -04:00
jwilson
7d5c4adc8d Use a class for KotlinJsonAdapterFactory. 2017-05-14 20:01:26 -04:00
jwilson
494992dab8 Support more kinds of properties in KotlinJsonAdapter
This makes it possible to have synthetic properties that have no
state.

Also test properties that are synthetic and have no backing field.

Closes: https://github.com/square/moshi/issues/299
2017-05-07 16:18:12 -04:00
Jesse Wilson
c65b3bf1cb Import jsr305 and use it to mark @Nullable stuff. (#297) 2017-05-06 20:31:24 -04:00
jwilson
cd1542363d KotlinJsonAdapter shouldn't convert enums.
Closes: https://github.com/square/moshi/issues/284
2017-04-21 09:54:45 -05:00
Christian Brüggemann
e76110b4b1 Fix Factory visibility (#282)
* Fix Factory visibility

* Remove redundant constructor keyword
2017-04-20 17:26:57 -05:00
jwilson
6112993919 Handle nulls symetrically in KotlinJsonAdapter.
When writing nulls we omit them, and when a value is omitted we assume
it is null.
2017-04-20 08:38:18 -05:00
Jesse Wilson
81bbe870f1 KotlinJsonAdapter (#281)
* Add kotlin-module with support for Kotlin data classes

* Naming and style changes to KotlinJsonAdapter.

Biggest changes:

 * Attempt to support regular classes and data classes
 * Avoid parameter hashing when indexing is sufficient for
   constructor parameters
2017-04-18 23:51:37 -04:00