Commit graph

44 commits

Author SHA1 Message Date
Jake Wharton
4f3f74f016
Merge pull request #515 from square/eric.versions
Group dependency version codes together.
2018-04-27 10:27:41 -04:00
Eric Cochran
1589ca8ddb Group dependency version codes together. 2018-04-25 16:40:20 -07:00
Eric Cochran
0d8b5efaa1
Update Error Prone to 2.3.1. 2018-04-25 16:37:46 -07:00
Eric Cochran
14f2dcc357
Update to Okio 1.14.0. 2018-04-06 17:10:33 -07: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
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
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
Sean Sullivan
b06f65d2e9 kotlin 1.1.60 2017-11-24 16:27:37 -05:00
Eric Cochran
b7a91e0557 Update to Error Prone 2.1.2. (#384) 2017-11-06 11:49:22 -08:00
Eric Cochran
e0ad48cd97 Update to Kotlin 1.1.51. 2017-10-28 10:07:05 +01: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
c8d8ee1fff Upgrade to Okio 1.13. 2017-05-14 21:58:48 -04:00
Jesse Wilson
c65b3bf1cb Import jsr305 and use it to mark @Nullable stuff. (#297) 2017-05-06 20:31:24 -04:00
jwilson
0ea1959b7e Enable Checkstyle 7.7. 2017-05-06 14:48:55 -04: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
Jake Wharton
05b0a46961 Add error-prone compiler. (#259)
* Fix error-prone warning

* Add error-prone compiler.

* Suppress warning about calling getClass() on annotation.
2017-02-14 22:28:24 -05:00
jwilson
49092ece96 [maven-release-plugin] prepare for next development iteration 2017-02-04 15:20:11 -05:00
jwilson
d075a3e56a [maven-release-plugin] prepare release moshi-parent-1.4.0 2017-02-04 15:20:05 -05:00
jwilson
e1809aa6f9 [maven-release-plugin] prepare for next development iteration 2016-10-21 09:35:13 -04:00
jwilson
6d623663cb [maven-release-plugin] prepare release moshi-parent-1.3.1 2016-10-21 09:35:10 -04:00
jwilson
4ff50c47ac [maven-release-plugin] prepare for next development iteration 2016-10-15 14:18:34 -04:00
jwilson
71ded8d091 [maven-release-plugin] prepare release moshi-parent-1.3.0 2016-10-15 14:18:31 -04:00
Jake Wharton
e01c89cef6 Okio 1.11.0. 2016-10-12 01:09:54 -04:00
Jake Wharton
42caa166f4 Point at the latest Okio. 2016-07-08 18:01:08 -04:00
jwilson
23e6d36a8b [maven-release-plugin] prepare for next development iteration 2016-05-28 14:27:08 -04:00
jwilson
5f0e509b8d [maven-release-plugin] prepare release moshi-parent-1.2.0 2016-05-28 14:27:04 -04:00
jwilson
3477c4d743 Upgrade to Okio 1.8.0. 2016-05-02 00:48:36 -04:00
jwilson
4925755ffa Optimize reading one of several expected values with Selection
This isn't yet public API.

This relies on an unreleased Okio API.

This has a significant impact on performance. I measured parsing performance
improve from 89k ops/sec to 140k ops/sec on one benchmark.
2016-04-17 20:15:07 -10:00
jwilson
ad3506ffed [maven-release-plugin] prepare for next development iteration 2016-01-18 17:17:10 -05:00
jwilson
30a4c3c92e [maven-release-plugin] prepare release moshi-parent-1.1.0 2016-01-18 17:17:08 -05:00
jwilson
dd505172ca Update changelog for 1.1.0. 2016-01-18 17:16:20 -05:00
jwilson
e6a77041a1 [maven-release-plugin] prepare for next development iteration 2015-09-27 13:25:21 -04:00
jwilson
e93e6574ca [maven-release-plugin] prepare release moshi-parent-1.0.0 2015-09-27 13:25:18 -04:00
jwilson
1c6bebac1d RFC3339 adapter.
Much thanks to Jackson for doing all the real work.
2015-09-26 18:51:50 -04:00
jwilson
c9b2dbe395 [maven-release-plugin] prepare for next development iteration 2015-06-16 07:45:59 -04:00
jwilson
46a8a880e9 [maven-release-plugin] prepare release moshi-parent-0.9.0 2015-06-16 07:45:57 -04:00
jwilson
d01c5782c3 Initial round of Moshi docs. 2015-06-16 07:35:41 -04:00
jwilson
912c07dafa Save an allocation by using Okio instead of substring. 2015-05-25 06:45:00 -07:00
jwilson
08becc119a Big start into ClassAdapter.
This borrows from Gson's UnsafeAllocator. I didn't actually
borrow much from Gson's reflective type adapter, but I'll need
to review that in follow up to see if I forgot anything that
Gson covers.

Most interesting design decision here is that fields are
serialized in alphabetical order. Also we're pretty nice
around detecting field collisiosn and failing early.
2015-03-23 00:13:04 -04:00
Jake Wharton
f6cee31e78 Update Okio, JUnit, and AssertJ to latest. 2014-12-22 10:22:01 -08:00
Jesse Wilson
93eddc9069 Initial JsonAdapter structure.
This is similar to the way Gson does its type adapters: factories that
can delegate and compose.

It's different because annotations are fundamental to the design.

It's also different because there are no APIs to convert to and from
JSON on the central object: instead callers must get the JSON adapter
they're interested in and do that there. This is potentially more
efficient because applications can hold the adapter they need.
2014-08-11 08:37:13 -04:00
Jesse Wilson
ac1b1027f8 Use indexOfElement in JsonReader.
This means we don't need to re-navigate through the segments
for every single character. Should be a small performance win.
2014-08-10 01:04:56 -04:00
Jesse Wilson
ff08c841f1 Basic project structure. 2014-08-09 12:19:29 -04:00