Commit Graph

390 Commits

Author SHA1 Message Date
Jesse Wilson
00dcac60d4 Implement peekJson() for JsonValueReader
The JsonUtf8Reader variant relies on an update to Okio that we're
not quite ready for.

This one became straightforward after I changed out the iterators
to be cloneable. That's necessary to split one iterator into two.
It's too bad the platform's built-in iterators are not cloneable;
that would have been convenient and potentially more efficient.

Related to https://github.com/square/moshi/issues/672
2018-09-24 23:21:07 -04:00
Jesse Wilson
2cb81857ac [maven-release-plugin] prepare for next development iteration 2018-09-24 22:55:49 -04:00
Jesse Wilson
9a652f8788 [maven-release-plugin] prepare release moshi-parent-1.7.0 2018-09-24 22:55:35 -04:00
Jesse Wilson
026d16ba68 Don't include the 'internal' package in Javadocs 2018-09-24 22:35:29 -04:00
Jesse Wilson
735f0c39f7 Upgrade Kotlin, AssertJ, compile-testing, and kotlin-metadata dependencies 2018-09-24 21:48:25 -04:00
Eric Cochran
5a46cd6bd5 Use BufferedSource.indexOf instead of loops. (#677)
Cleanup of a rare code path for block comments in lenient readers.
2018-09-20 21:20:11 -07:00
Benoit Quenaudon
df730cafb9 Fix JsonQualifiers test 2018-09-13 15:02:06 -04:00
Eric Cochran
895c3ddb49 Track field names in the adapter lookup stack. (#616)
* Track field names in the adapter lookup stack.

This allows for an error message that includes field names to track down the cause of adapter creation failure for deeply nested structures.

* Use a single stack in Moshi client.

* Make optional fieldName parameter public API.

* Simplify error message.
2018-09-12 22:27:58 -04:00
Jesse Wilson
83b6b26e63 Merge pull request #659 from square/eric.exception-cause
Add exception cause for method adapter creation.
2018-09-12 22:24:22 -04:00
Benoit Quenaudon
c606f43a3d Don't reflect on androidX 2018-09-12 15:11:42 -04:00
Eric Cochran
46a42bc7ed Add exception cause for method adapter creation. 2018-09-11 22:25:09 -07:00
Jesse Wilson
76cd590ca3 Generate nicer stacktraces when creating a generated adapter fails.
Otherwise we end up with many InvocationTargetExceptions layered in, which makes
it difficult to identify what actually failed.
2018-09-11 22:02:54 -04:00
Eric Cochran
e7c745aac8 Make generated adapters null-safe.
This is in alignment with the lookup for Java and Kotlin reflective adapters.
2018-09-10 16:31:24 -07:00
Jesse Wilson
2a593da06c Merge pull request #628 from gabrielittner/master
Embed ProGuard rules in the jar
2018-09-08 14:58:44 -04:00
Gabriel Ittner
24e0777ebd add period to comments 2018-09-07 08:04:56 +02:00
Jorge Antonio Díaz-Benito Soriano
56e67088a9 Remove unnecessary isAccessible check
https://github.com/square/moshi/issues/624
2018-08-19 20:46:43 +02:00
Gabriel Ittner
4bbc5b2ff8 Embed ProGuard rules in the jar 2018-08-19 11:14:47 +02:00
Eric Cochran
137ffc992f Fix incorrect path in enum adapter error message. (#613) 2018-08-06 22:46:41 -07:00
Eric Cochran
627e62f507 Fix hasNext to return false at document end. 2018-06-22 15:18:22 -07:00
Eric Cochran
df3a6ce2ae Remove redundant "to" in doc. 2018-05-23 12:28:07 -07:00
Eric Cochran
d31f3c2482 Add more CheckReturnValues for JsonReader.
This encourages skipName over nextName.
2018-05-15 18:37:29 -07:00
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
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
7b1177adbc Merge pull request #503 from square/eric.write-from-source
Allow writing out raw JSON.
2018-05-06 21:11:34 -04:00
Zac Sweers
4b610329bd Full JsonQualifier support in kotlin codegen. 2018-05-06 21:09:28 -04:00
Eric Cochran
b848f1cc52 Add JsonReader.skipName. 2018-04-30 18:41:18 -07:00
Eric Cochran
a0cd8a4fc0 Allow writing out raw JSON. 2018-04-29 23:49:47 -07:00
Jesse Wilson
b96397f6eb Merge pull request #500 from square/eric.coherent-nesting-problem-error-message
Add coherent error message for uneconded map keys.
2018-04-28 21:14:45 -04:00
Eric Cochran
44e6fbd067 Add coherent error message for unencoded map keys. 2018-04-25 11:36:47 -07:00
Eric Cochran
b125f06e70 Fix up out-of-date comments. 2018-04-24 13:17:40 -07:00
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
Eric Cochran
b860b6da4f Make error message for dangling names consistent. (#501) 2018-04-15 19:48:32 -07:00
Jesse Wilson
9401a810f0 Support generated adapters for Kotlin superclasses 2018-04-15 14:37:49 -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
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
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
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
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
Eric Cochran
dc450e6192 Resolve generic property types in KotlinJsonAdapter. 2018-04-03 17:37:38 -07: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
Eric Cochran
e6c2ebedde Disallow null annotation set in adapter lookup. (#460) 2018-03-10 06:42:07 -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