Commit Graph

840 Commits

Author SHA1 Message Date
Jesse Wilson
cff20193c2 [maven-release-plugin] prepare release moshi-parent-1.10.0 2020-08-26 21:38:36 -04:00
Jesse Wilson
c370385fdc Update changelog for 1.10.0 2020-08-26 21:36:09 -04:00
Zac Sweers
a5dbc1d642 Update to Kotlin 1.4.0 (#1191)
* Update to Kotlin 1.4.0

* Remove moshi-kotlin rules in favor of Kotlin's

* Ignore tests for now

* Update to OptIn

* Update test for kotlin 1.4 behavior
2020-08-25 22:51:44 -04:00
Jesse Wilson
1283ceed94 Merge pull request #1185 from square/jwilson.0801.public_promoteNameToValue
Make JsonReader.promoteNameToValue() a public API
2020-08-05 11:10:24 -04:00
Jesse Wilson
1dd9cd0b3b Make JsonReader.promoteNameToValue() a public API 2020-08-05 10:23:24 -04:00
Jesse Wilson
50d09d476b Merge pull request #1182 from square/jwilson.0730.simplify
Simplify the internals of PolymorphicJsonAdapterFactory
2020-07-30 23:12:37 -04:00
Zac Sweers
aa18c6857c Expose getStrings() option on JsonReader.Options (#1180)
* Expose getStrings() option on JsonReader.Options

Resolves #1173

* Fix clone

Co-authored-by: Jake Wharton <github@jakewharton.com>

* Add mutation check

* Use set and make it unmodifiable

* Back to list

* strings()

* No clone()

Co-authored-by: Jake Wharton <github@jakewharton.com>
2020-07-30 23:10:41 -04:00
Jesse Wilson
2b5b3b5f8e Simplify the internals of PolymorphicJsonAdapterFactory
We don't need a custom JsonAdapter subclass - we can just call through
unconditionally and fail if the type is unexpected.
2020-07-30 22:34:09 -04:00
Samuele Maci
cd31e5ce52 Extend PolymorphicJsonAdapterFactory to allow custom handling of unknown labels (#1094)
* PolymorphicJsonAdapter uses JsonAdapter as fallback value instead of defaultValue

* PolymorphicJsonAdapterFactory uses fallbackJsonAdapter instead of (defaultValue, defaultValueSet)

* Add testing coverage
2020-07-30 22:01:42 -04:00
Jesse Wilson
61e5ff34cc Merge pull request #1152 from Tolriq/R8_fix
Fix R8 keeping all Kotlin metadata when using Moshi.
2020-07-30 21:41:54 -04:00
Jesse Wilson
d6d9b5d8bc Merge pull request #1181 from ZacSweers/patch-4
Update README notes about R8/proguard
2020-07-30 21:39:41 -04:00
Zac Sweers
3eb95f277c Update README notes about R8/proguard
Resolves #1166
2020-07-29 00:07:41 -04:00
Jesse Wilson
7f2630daee Merge pull request #1168 from vladimirov001/kotlin_verify_error_on_android_kitkat_devices
R8 triggers VerifyError on KitKat devices
2020-06-26 07:27:15 -04:00
Oleg Vladimirov
6eb65908e0 bugfix 2020-06-26 13:28:00 +03:00
Jake Wharton
7462d32d9d Merge pull request #1161 from ZacSweers/patch-3
Fix typo in 1.9.3 changelog notes
2020-06-15 09:41:26 -04:00
Zac Sweers
d55248b4ab Fix typo in 1.9.3 changelog notes 2020-06-15 02:35:13 -04:00
Jake Wharton
7829f9a65b Prepare version 1.9.3
(cherry picked from commit c7d0766c03842a411d52d691de343dd4f874f1d7)
2020-06-12 11:42:08 -04:00
Jake Wharton
d07040ce17 Merge pull request #1155 from square/jw/wrapper/2020-06-08
Add Maven wrapper
2020-06-10 08:32:38 -04:00
Jake Wharton
c63f7cc5d0 Add Maven wrapper 2020-06-08 20:09:58 -04:00
Tolriq
8c8c5977a7 R8 now have automatic detection of Class.forName and auto generate keep rules.
This makes application build with Moshi to keep unwanted Kotlin Metadata that have a huge impact on APK size.

After discussion with R8 team, there's currently no solution to avoid this other than using the trick in this PR.

Fixes https://github.com/square/moshi/issues/1115
2020-06-04 18:09:10 +02:00
Ryan Harter
dd8611a1d9 Merge pull request #1080 from square/z/resolveRealTypes
Fix resolution of types in superclass settable properties
2020-05-26 17:53:45 -05:00
Jake Wharton
0c85eae34a Merge pull request #1142 from sarthakz9/patch-1
small correction in given example
2020-05-18 09:46:41 -04:00
sarthak sehgal
976a891568 small correction in given example 2020-05-18 12:11:24 +05:30
Jake Wharton
db803ffa79 Merge pull request #1121 from angusholder/improve-collections-errors
Improve error when incorrectly trying to use a collection class like ArrayList instead of List
2020-04-09 21:23:41 -04:00
Graham Lea
d06758d092 Document thread safety 2020-04-09 21:22:49 -04:00
Angus Holder
2a9177168b Improved error when using collection classes by mistake
A new user of Moshi might try to make a class like

    data class Response (
        val users: ArrayList<User>
    )

Then when trying to create a JsonAdapter for it, they get an unhelpful error
message like

    Platform class java.util.ArrayList in java.util.ArrayList<java.lang.String>
    requires explicit JsonAdapter to be registered

which doesn't explain what they should do to fix the problem. In fact what it
hints towards is that the user should implement a JsonAdapter for ArrayList,
when really they just need to change the type to List!

Now the error looks like

    No JsonAdapter for java.util.ArrayList<java.lang.String>, you should use
    List instead of ArrayList (Moshi only supports the collection interfaces
    by default).
2020-04-09 21:19:13 -04:00
Jake Wharton
b413423d05 Merge pull request #1098 from square/jakew/json-value-writer/2020-02-14
Add JsonWriter.jsonValue API
2020-02-15 18:42:59 -05:00
Jake Wharton
0790296cc7 Add JsonWriter.jsonValue API
This is symmetric with JsonReader.readJsonValue in that it writes an Object comprised of maps, lists, and some scalars.
2020-02-15 18:38:39 -05:00
Zac Sweers
d64033ed94 Fix reflection names in generated proguard files (#1088)
* Fix reflection names in generated proguard files

Proguard wants to speak reflection names

* Opportunistic clean up proguard tests

This ensures we fail the test if there are any unexpected ones
2020-01-30 22:58:10 -05:00
Zac Sweers
1edcb77f76 Specify exactly which typevars are allowed to top level 2020-01-18 23:11:17 -05:00
Zac Sweers
76b4ec9f92 Add another twist 2020-01-18 23:10:40 -05:00
Zac Sweers
3f0d763ce1 Opportunistic - suppress RedundantExplicitType 2020-01-18 23:08:44 -05:00
Zac Sweers
4e84451d6e Resolve type arguments correctly for supertype settable properties
Resolves #1046
2020-01-18 22:52:18 -05:00
Zac Sweers
a73b932429 Always emit full types
Effectively reverts https://github.com/square/moshi/pull/1041
2020-01-18 22:47:56 -05:00
Zac Sweers
04f414f600 Add ComplexGenericsInheritanceTest 2020-01-18 22:46:54 -05:00
Zac Sweers
52cf86d609 Tweak README nullSafe() example (#1073)
Resolves #1003
2020-01-15 13:29:24 -05:00
Zac Sweers
4fbf89cd49 Fix mask count in proguard rule gen (#1075)
* Fix mask count in proguard rule generation

Signed,
Person that always forgets how to do modulo counting

* Update tests
2020-01-15 02:42:52 -05:00
Zac Sweers
9a10976aab Minor processor cleanups (#1070)
* Share cachedClassInspector across all rounds

* Don't proceed if previous round failed
2020-01-14 16:28:35 -05:00
Zac Sweers
89b166f9cd Use actual canonical name rather than implicit toString() (#1069) 2020-01-14 15:50:14 -05:00
Zac Sweers
e45d9e04bd Add missing semicolons (#1068) 2020-01-14 15:26:40 -05:00
Zac Sweers
debb7d3160 Generate proguard rules for code gen on demand (#1067)
* Extract target constructor signature into TargetConstructor.kt

We'll need this to know what the runtime types are for proguard rules

* Add ProguardConfig

* Wire in proguard config

* Write proguard configs out with adapters

* Add full tests

* Now remove the rules!

* Ignore on inline classes for now

* Pass adapter constructor params correctly
2020-01-14 14:59:10 -05:00
Zac Sweers
f891c8187b Check types parameter size in init (#1063)
* Add types size check in code gen

Resolves #932

* Add more useful message for mismatched generics lookup

* Add tests

* Style
2020-01-14 01:50:53 -05:00
Nicklas Ansman Giertz
cc4b5b3ad2 Improve the way Json.name is fetched for codegen (#1059)
* Improve the way Json.name is fetched for codegen

* Remove the comment for jsonName

* Add a test for json names with quotation marks

* Fix the broken tests
2020-01-10 21:32:23 -05:00
Zac Sweers
365e955381 Update to KotlinPoet 1.5.0 (#1062) 2020-01-10 21:05:21 -05:00
Zac Sweers
40a829ef18 Don't linebreak keys with spaces (#1053)
* Don't linebreak keys with spaces

Resolves #1052

* Update kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt
2019-12-12 02:53:25 -05:00
Zac Sweers
c3a1ba711c Omit unnecessary generic type from standard constructor call (#1041)
These were redundant. Was `return Foo<T>(...)` and is now `return Foo(...)`
2019-12-05 22:37:38 +01:00
Zac Sweers
14cb9e4bbb Add LocalVariableName to common suppressions (#1040)
* Add LocalVariableName to common suppressions

NameAllocator will add underscores to names, which kotlin doesn't like for stylistic reasons

* Simplify structure a bit

Keeping track of template counts is error prone and would have failed only at runtime
2019-12-05 22:37:26 +01:00
Zac Sweers
791ff3211e Update to Kotlin compile testing 1.2.4 (#1014)
* Update to Kotlin compile testing 1.2.4

This allows us to un-toe-hold a test from before

* Fix trailing newline

* Add class-based alternative

* Use updated test API

* Update to 1.2.5

* Update to Kotlin 1.3.60
2019-12-05 22:37:02 +01:00
Zac Sweers
32c5d48ab1 Strip type annotations from TypeRenderer and asTypeBlock() (#1039)
Resolves #1033
2019-12-05 22:35:57 +01:00
Zac Sweers
0dfea712bb Always check for DefaultConstructorMarker class (#1038)
Reported by a Googler - We currently gate the lookup of the class on the presence of `Metadata`. However, `Metadata` might be justifiably stripped by Proguard/R8, even though `DefaultConstructorMarker` might still be present. This means Moshi's defaults invocation is likely broken on (at least) R8 builds without this.

Workaround until next release is to keep Metadata annotations
2019-11-24 22:52:59 -05:00