Commit Graph

1369 Commits

Author SHA1 Message Date
Egor Andreevich
ae421b1909 Move repo uploads to S01 (#1471) 2021-12-23 11:44:24 -05:00
Jake Wharton
5cf5f9664c Merge pull request #1464 from square/z/staticRecords
Remove redundant static modifiers on records
2021-12-20 16:54:51 -05:00
Zac Sweers
82987854df Remove redundant static modifiers on records
They are implicit
2021-12-20 16:46:39 -05:00
Zac Sweers
2e15a3fa72 Update moshi version used for japicmp (#1459) 2021-12-12 04:03:03 -05:00
Zac Sweers
1d60d4cf73 Document Json.ignore in the README (#1456) 2021-12-09 15:37:50 -05:00
Zac Sweers
16ebad5a7d Add KSP docs to README (#1455)
* Add KSP docs to README

* Open KSP

* spotless
2021-12-09 11:16:47 -05:00
Jesse Wilson
7401e82b9b Submit to Javadoc's draconion heading ordering rule (#1452)
Whoever thought this was a good idea is wrong.

    > Task :moshi:javadoc
    /home/runner/work/moshi/moshi/moshi/src/main/java/com/squareup/moshi/JsonWriter.java:40: error: heading used out of sequence: <H3>, compared to implicit preceding heading: <H1>
     * <h3>Encoding JSON</h3>
       ^
    /home/runner/work/moshi/moshi/moshi/src/main/java/com/squareup/moshi/JsonReader.java:40: error: heading used out of sequence: <H3>, compared to implicit preceding heading: <H1>
     * <h3>Parsing JSON</h3>
       ^
2021-12-09 06:07:44 -05:00
Jesse Wilson
7578984f25 Change the directory structure to match our modules (#1451) 2021-12-08 23:52:51 -05:00
Jesse Wilson
d5d172c3bb Switch to the Vanniktech base plugin for publishing (#1450)
* Switch to the Vanniktech base plugin for publishing

Move configuration out of build.gradle files and into build.gradle.kts files.
Sign published builds.
Support publishing release builds from GitHub actions.

* Update build.gradle.kts

Co-authored-by: Zac Sweers <zac.sweers@gmail.com>

Co-authored-by: Zac Sweers <zac.sweers@gmail.com>
2021-12-08 23:35:49 -05:00
Jesse Wilson
9d2b9054da Prepare next development version. 2021-12-08 21:56:51 -05:00
Jesse Wilson
09a4543297 Prepare for release 1.13.0. 2021-12-08 21:56:39 -05:00
Jesse Wilson
bc441ad7f3 Don't mangle property names that contain a dollar sign (#1446)
Without this fix the new test fails like this:

    value of: toJson(...)
    expected: {"$a":"apple","$b":"banana"}
    but was : {"${'$'}a":"apple","$b":"banana"}
2021-12-05 21:07:27 -05:00
Zac Sweers
fb5dd08168 KSP followups from #1393 (#1448)
* Rename to unwrapTypeAliasInternal + simplify

* Move down isAnyNullable

* Make dynamic explicit

* Clean up supertypes doc and filtering

* Switch to invoke extensions

* Just best guess the annotation

* Clean up redundant sequence and use a regular loop

* element -> type

* supertypes -> superclasses

* Spotless

* Fix copyright

* Add multiple messages check

* Link issue

Co-authored-by: Jesse Wilson <jesse@swank.ca>
2021-12-05 20:34:37 -05:00
Jesse Wilson
f57d7200f3 Attribute copyright to the actual owner (#1447)
I believe that's this:
https://github.com/google/ksp/blob/main/api/src/main/kotlin/com/google/devtools/ksp/utils.kt
2021-12-05 20:21:38 -05:00
Jesse Wilson
3cbd5c327a Fail gracefully when a primitive value is absent. (#1445)
Without this we get an AssertionError, which is the wrong exception
type for a JSON schema mismatch:

    java.lang.AssertionError: java.lang.NullPointerException: Cannot invoke "java.lang.Number.intValue()" because the return value of "sun.invoke.util.ValueConversions.primitiveConversion(sun.invoke.util.Wrapper, Object, boolean)" is null
      at com.squareup.moshi.RecordJsonAdapter.fromJson(RecordJsonAdapter.java:168)
      at com.squareup.moshi.internal.NullSafeJsonAdapter.fromJson(NullSafeJsonAdapter.java:41)
      at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:70)
      at com.squareup.moshi.records.RecordsTest.absentPrimitiveFails(RecordsTest.java:257)
    Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Number.intValue()" because the return value of "sun.invoke.util.ValueConversions.primitiveConversion(sun.invoke.util.Wrapper, Object, boolean)" is null
      at java.base/sun.invoke.util.ValueConversions.unboxInteger(ValueConversions.java:81)
      at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
      at com.squareup.moshi.RecordJsonAdapter.fromJson(RecordJsonAdapter.java:156)
      ... 46 more
2021-12-04 19:10:35 -05:00
Jesse Wilson
75abba37ef Use functions in Util where possible (#1444) 2021-12-04 17:22:12 -05:00
Jesse Wilson
81bf3b1835 Don't wrap exceptions thrown by component adapters (#1443) 2021-12-04 16:38:56 -05:00
Jesse Wilson
cdcf0da4ee Fix a crash when combining generics and records (#1442)
Without the fix the test fails like so:

    No JsonAdapter for T (with no annotations)
    for T
    for java.util.List<T>
    for com.squareup.moshi.records.RecordsTest$IndirectGenerics<java.lang.Long>
    for class com.squareup.moshi.records.RecordsTest$HasIndirectGenerics
    java.lang.IllegalArgumentException: No JsonAdapter for T (with no annotations)
    for T
    for java.util.List<T>
    for com.squareup.moshi.records.RecordsTest$IndirectGenerics<java.lang.Long>
    for class com.squareup.moshi.records.RecordsTest$HasIndirectGenerics
      at com.squareup.moshi.Moshi$LookupChain.exceptionWithLookupStack(Moshi.java:389)
      at com.squareup.moshi.Moshi.adapter(Moshi.java:158)
      at com.squareup.moshi.Moshi.adapter(Moshi.java:106)
      at com.squareup.moshi.Moshi.adapter(Moshi.java:75)
2021-12-04 16:31:58 -05:00
Zac Sweers
751e8219e9 Fix code cleanups (#1441)
* Fix immutable properties

It was intentionally designed the previous way

* Restore limit in for loop

* Another ImmutableProperties
2021-11-30 21:56:00 -05:00
Zac Sweers
9f81ac897a Revert "Omit adapter field names now that we directly instantiate annotations (#1436)" (#1439)
This reverts commit 4a6cfb4d58.
2021-11-30 21:43:48 -05:00
Zac Sweers
fb8c7b50fc Deprecate Types.getFieldJsonQualifierAnnotations (#1440) 2021-11-30 21:43:39 -05:00
Zac Sweers
ace45a29cf Don't handle copyrights in spotless (#1438)
It can get it wrong too easily
2021-11-30 21:34:35 -05:00
Zac Sweers
9a9cc450c6 Remove ksp.kt copy (#1437) 2021-11-30 21:21:33 -05:00
Zac Sweers
4a6cfb4d58 Omit adapter field names now that we directly instantiate annotations (#1436) 2021-11-30 16:23:47 -05:00
Zac Sweers
aaadbf4963 Update kotlinx-metadata to 0.4.0 (#1431) 2021-11-23 10:00:54 -05:00
Jake Wharton
81ad3933b0 Merge pull request #1427 from Tolriq/patch-1
Update proguard rules for R8 3.1
2021-11-18 06:51:52 -05:00
Tolriq
9ce039d637 Update proguard rules for R8 3.1
R8 3.1 in full mode have made improvements to annotation removal.
Current rules are not enough to ensure that JsonQualifier  annotatated class are kept.

See https://issuetracker.google.com/issues/206656057
2021-11-18 08:36:22 +01:00
Zac Sweers
73553286fb Upgrade to Kotlin 1.6 + always instantiate annotations (#1425) 2021-11-17 12:46:47 -05:00
Zac Sweers
9440e5c7d0 Update to KSP 1.0.1 and use new jvm modifiers resolver API (#1422)
* Update to KSP 1.0.1 and use new jvm modifiers resolver API

This allows us to fully support transient across compilation boundaries

* Copy in KSP-supported KCT for now

* Update CI refs

* Move up transient check to the right place

Wasn't actually looking at the added annotation later 🤧

* Try regular RC?

* Skip that matrix for now
2021-11-15 11:25:15 -05:00
Zac Sweers
85ba5bf188 Update to Gradle 7.3 (#1419)
https://docs.gradle.org/7.3/release-notes.html

Highlights include
- Java 17
- Tasks can mark themselves as untracked
2021-11-15 10:44:39 -05:00
Zac Sweers
954ca46b9e Add @Json.ignore (#1417)
* Default Json.name to an unset value

* Promote shared transient tests to DualKotlinTest

* Add new ignore property to Json

* Support it in ClassJsonAdapter

* Mention no enum/record support

* Support in KotlinJsonAdapter

* Rework code gen API to know of "ignored"

* Support in apt code gen

* Support in KSP

* Update old non-working transient example test

* Synthetic holders

* Use field on both
2021-11-08 11:16:57 -05:00
Zac Sweers
48e6dd3f03 Support externally-compiled transient property recognition in KSP (#1416) 2021-11-03 15:49:28 -04:00
Sangeet Narayan
92add003fe Update README.md to include Kotlin Examples (#1355) 2021-10-31 16:25:55 -04:00
Zac Sweers
c288ad6133 Switch from internal to experimental internal annotation (#1410) 2021-10-30 12:15:08 -04:00
Zac Sweers
313683fa98 Parameterize kotlin test infra on CI (#1407) 2021-10-25 11:00:56 -04:00
Zac Sweers
7dd3b39376 Expose maven gradle props as env instead (#1408) 2021-10-22 16:17:32 -04:00
Zac Sweers
b8fbe38118 Support direct annotation instantiation in code gen on Kotlin 1.6 (#1390) 2021-10-22 13:43:09 -04:00
Zac Sweers
a9eaa849e5 Only assign setters if present (#1405)
* Only assign setters if present

Rather than generating

```kotlin
val result: Content
result = Content()
result.content = if (contentSet) content else result.content
result.text = if (textSet) text else result.text
```

This will now conditionally set

```kotlin
val result: Content
result = Content()
if (contentSet) {
  result.content = content
}
if (textSet) {
  result.text = text
}
```

* Spotless
2021-10-22 12:18:59 -04:00
Zac Sweers
3a88349f34 Add --stacktrace to snapshot publishing (#1406)
Trying to diagnose why these are failing
2021-10-22 12:18:48 -04:00
Zac Sweers
862ff7ddcd Update to JDK 17 (#1394)
Everything still targets JDK 8 (non-records) or JDK 16 (records only)
2021-10-16 02:18:51 -04:00
Zac Sweers
2db351f8ed Upstream KSP implementation (#1393) 2021-10-16 01:52:04 -04:00
Zac Sweers
de8bbf12f5 Update KotlinPoet to 1.10.0 (#1396) 2021-09-20 16:13:56 -04:00
Chitranshi Srivastava
628a193d69 fix: corrected a grammatical error. (#1298) 2021-09-12 20:55:53 -04:00
iury souza
29d2f0f0ed Update README to include enum section in ProGuard/R8 rules (#1354) 2021-09-12 20:54:44 -04:00
Zac Sweers
5756136a72 Move apt-specific classes to apt package (#1392) 2021-09-09 22:14:29 -04:00
Zac Sweers
213fb33012 Fix snapshots (#1385) 2021-08-27 13:28:20 -04:00
Zac Sweers
6947ab00d0 Modernize build a bit (#1383) 2021-08-23 17:09:59 -04:00
Zac Sweers
95250b0359 Implement reflective support for Java Records (#1381)
* Standardize around JDK 8

* Update GJF to support newer JDKs

* Fix misc java 8 issues in tests

* Prepare java 16/records checking at runtime

* Implement real RecordJsonAdapter

* Spotless

* Prepare build for JDK 16+

* Fix property name for kapt

* Small cleanup

* Make FallbackEnum java-8 happy

* Remove animalsniffer

* Fix format

* Add opens for ExtendsPlatformClassWithProtectedFields

* Return null every time in shim for main tests

* Use JDK 16 + release 8 to replace animalsniffer

* Simplify accessor accessible handling

* Remove manifest attrs

* Fix typo

* Fix KCT tests + upgrade it

* Cover another

* Try explicit kotlin daemon args for java 17?

* Disable 17-ea for now until kotlin 1.5.30

* Add JsonQualifier and Json(name) tests + fix qualifiers

* Ensure constructor is accessible

* GJF it properly

* GJF 1.11

* Unwrap InvocationTargetException

* Use MethodHandle for constructor

* Use MethodHandle for accessor too

* Revert "Remove manifest attrs"

This reverts commit 3eb768fd6904bb5c979aa01c3c182e0fb9329d62.

* Proper MR jar

* *actually* fix GJF, which wasn't getting applied before

We can just enable this everywhere now since we require JDK 16 anyway

* Make IDE happy about modules access

* Fixup records tests to play nice with modules

Gotta be public

* Add complex smoke test

* Remove comment

Not a regression test in this case
2021-08-23 12:00:06 -04:00
Goooler
2572c29e42 Code cleanups 2021-08-18 14:51:52 -04:00
Jake Wharton
ce78d34c14 Merge pull request #1379 from Goooler/gradle
Update gradle 7.2
2021-08-17 08:32:24 -04:00