Commit Graph

1004 Commits

Author SHA1 Message Date
Zac Sweers
178a6858ff Switch fully over to dokka and fix accidental root project publishing (#1507) 2022-01-17 13:04:35 -05:00
Zac Sweers
47697c2601 Convert JsonReader to Kotlin (#1505)
* Rename .java to .kt

* Convert JsonReader to Kotlin

Made it sealed along the way like JsonWriter

Some of the properties had different docs for setting and getting, which dokka doesn't seem to have a nice way to differentiate. Went with a little marked up form but open to suggestions.

* Restore isLenient name to lenient

This plays nice for both java and kotlin consumers, as it's still isLenient to java consumers but not a source breaking change for kotlin

* Fix peek nullability and a kotlin source change

* Fix another nullability

* Use collection builders

* Ok this didn't work quite as I expected

* Update moshi/src/main/java/com/squareup/moshi/JsonReader.kt

Co-authored-by: Parth Padgaonkar <1294660+JvmName@users.noreply.github.com>

Co-authored-by: Parth Padgaonkar <1294660+JvmName@users.noreply.github.com>
2022-01-17 02:52:02 -05:00
Zac Sweers
e6081dc90e Skip nullchecks on known primitives (#1506) 2022-01-17 02:07:55 -05:00
Spencer Griffin
71c32934bf Convert ClassFactory.java to kotlin (#1469)
Co-authored-by: Spencer Griffin <sgriffin@ancestry.com>
2022-01-13 01:26:08 -05:00
Zac Sweers
ffaedac610 Don't suffix the value param when overriding (#1503) 2022-01-12 14:27:08 -05:00
Zac Sweers
1fdc61dc31 Update a few misc build deps (#1500) 2022-01-12 13:50:48 -05:00
Zac Sweers
9ac2ddf2db Finish up JsonWriter Kotlin conversion (#1501)
Co-authored-by: Zac Sweers <pandanomic@gmail.com>
Co-authored-by: Goooler <wangzongler@gmail.com>
2022-01-12 13:47:35 -05:00
Spencer Griffin
ff2f6e18d2 Convert ArrayJsonAdapter.java to kotlin (#1468)
Co-authored-by: Zac Sweers <pandanomic@gmail.com>
Co-authored-by: Spencer Griffin <sgriffin@ancestry.com>
2022-01-12 13:42:42 -05:00
Zac Sweers
396342b06b Convert RecordJsonAdapter to Kotlin (#1493) 2022-01-11 15:39:31 -05:00
Zac Sweers
d805ad1b5b Keep @FromJson/@ToJson-annotated methods in proguard (#1499) 2022-01-11 15:00:34 -05:00
Zac Sweers
1b582e4647 Convert JsonValueReader to Kotlin (#1487) 2022-01-11 13:29:16 -05:00
Zac Sweers
0a6565bb46 Convert JsonUtf8Writer to Kotlin (#1486) 2022-01-11 13:08:48 -05:00
Zac Sweers
ec3977160b Convert Types to Kotlin (#1488) 2022-01-11 12:55:33 -05:00
Sampath
8b30dacd1d Converted the read json list Java file to Kotlin (#1495) 2022-01-11 10:14:24 -05:00
Sampath
77645dee5c Update dokka to 1.6.10 (#1497) 2022-01-11 00:32:32 -05:00
Zac Sweers
156e9007fd Convert JsonValueSource to Kotlin (#1489)
* Rename .java to .kt

* Convert JsonValueSource to Kotlin
2022-01-10 12:23:09 -05:00
Zac Sweers
d7b70637d2 Convert MapJsonAdapter to Kotlin (#1492)
* Rename .java to .kt

* Convert MapJsonAdapter to Kotlin

* Pull up factory into companion object

* Spotless

* apicmp

* Use knownNotNull

* Use a template
2022-01-10 12:22:15 -05:00
Zac Sweers
31b7a11027 Inline Moshi extension functions to Moshi itself (#1496)
* Move inline extensions to Moshi(.Builder) directly

No need for the separation and it allows removing of the import

* Remove now-redundant imports
2022-01-10 12:22:02 -05:00
Zac Sweers
59afd4bb9b Convert JsonValueWriter to Kotlin (#1491)
* Rename .java to .kt

* Convert JsonValueWriter to Kotlin

* Use knownNotNull

* when of whens

Co-authored-by: Parth Padgaonkar <1294660+JvmName@users.noreply.github.com>

* Nix the return

* Clean up

Co-authored-by: Parth Padgaonkar <1294660+JvmName@users.noreply.github.com>
2022-01-10 12:21:14 -05:00
Zac Sweers
6e81499501 Convert StandardJsonAdapters to Kotlin (#1494)
* Rename .java to .kt

* Convert StandardJsonAdapters to Kotlin

* Inline factory to object

* Idiomatic cleanups + japicmp

* Fixes

* Another idiomatatic bit

* Use knownNotNull() where applicable
2022-01-10 12:14:07 -05:00
Zac Sweers
323d97c787 Convert JsonAdapter to Kotlin (#1475)
* Rename .java to .kt

* Convert JsonAdapter to Kotlin

Note that there's more to be done here I think, namely exploring removing the NonNull adapter and making the nullSafe() adapter public so that nullability is directly in the API. Saving that for another day though

* Update a couple usages

* Fix override

* Add exclusion for open

* Add `@Language` annotation for json strings

Allows the IDE to automatically make this pretty

* Spotless

* Nullable

Co-authored-by: Egor Andreevich <egor@squareup.com>

* When

Co-authored-by: Parth Padgaonkar <1294660+JvmName@users.noreply.github.com>

* Another when

* Spotless

Co-authored-by: Egor Andreevich <egor@squareup.com>
Co-authored-by: Parth Padgaonkar <1294660+JvmName@users.noreply.github.com>
2022-01-10 11:29:37 -05:00
Zac Sweers
6f8d690e6e Convert JsonScope to Kotlin (#1484)
* Rename .java to .kt

* Convert JsonScope to Kotlin

* Use buildString
2022-01-10 11:08:36 -05:00
Zac Sweers
2daf78337d Convert Collection adapter to Kotlin (#1485)
* Consolidate contract utils

* Rename .java to .kt

* Convert CollectionJsonAdapter to Kotlin

* Lift factory into companion object

* Update moshi/src/main/java/com/squareup/moshi/internal/Util.kt
2022-01-10 11:07:57 -05:00
Zac Sweers
32932cfb40 Convert exceptions to Kotlin (#1483)
* Rename .java to .kt

* Convert exceptions to kotlin

* Add missing empty constructor
2022-01-10 11:07:48 -05:00
Zac Sweers
56e1ae6404 Use Okio IOException in Kotlin classes (#1490)
More portability!
2022-01-07 21:02:16 -05:00
Sampath
50751a863a Latest version is 1.13.0 (#1482) 2022-01-07 13:14:24 -05:00
Sampath
846b9c3a45 EventJsonAdapter Kotlin sample update (#1481) 2022-01-07 10:44:18 -05:00
Vincent Stollenwerk
196ab7a132 Fix typo in README (#1480) 2022-01-06 17:26:10 -05:00
Zac Sweers
484d525db4 Convert adapters to Kotlin (#1460)
* Convert Rfc3339DateJsonAdapter

* Convert EnumJsonAdapter

* Convert PolymorphicJsonAdapterFactory

* Convert Rfc3339DateJsonAdapter and Iso8601Utils

* Doc indent fix

* Use template

* Address CR comments

* Spotless and jsr cleanup

* Couple small tweaks

* Remove toList()

* Use simpler map

* Inline GregorianCalendar

* Interp

* Fix copyright

* interp

* Fix another copyright

* Restore toList()
2022-01-06 15:15:48 -05:00
Zac Sweers
e2c346e1de Convert util package to Kotlin (#1461)
* Rename .java to .kt

* Convert NonNullJsonAdapter

* Rename .java to .kt

* Convert NullSafeJsonAdapter

* Fix missing null-check

* Rename .java to .kt

* Convert Util (initial pass)

* Push to top-level Util

* Use extensions and properties where possible

* Use knownNotNull

* Spotless

* Clean up impl type classes a bit

* Update code gen

* Use extension for resolving

* Spotless

* Fix master conflicts

* Rename to toStringWithAnnotations()

* for (t in args.indices) {

* for (i in interfaces.indices) {

* Template
2022-01-06 14:54:13 -05:00
Zac Sweers
e5e4c48767 Convert Moshi annotations to Kotlin (#1472) 2022-01-03 13:53:56 -05:00
Zac Sweers
82cf56ab76 Fix javadoc task and snapshots (#1474)
The javadoc task assumes every doc starts with h1 and thus using them anywhere in the body after the start is an error ¯\_(ツ)_/¯. This just changes them to h2
2021-12-26 17:55:43 -06:00
Zac Sweers
f0b886f129 Fix exhaustive when in JsonUtf8Reader (#1473)
* Fix exhaustive when in JsonUtf8Reader

This accidentally snuck into master because it predates the Kotlin 1.6 upgrade

* Fix nextInt too

* Clean up a few little warnings opportunistically

* Fix comment

* Use knownNotNull
2021-12-26 17:07:52 -06:00
Parth Padgaonkar
c49daf907b JsonUtf8Reader --> Kt (#1400)
* initial attempt

* passing tests

* cleanup

* Apply suggestions from code review

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

* split `also` to two lines

* remove !! and labels

* spotless

* Apply suggestions from code review

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

* clean up a few more things

* pull duplicated code into an inline fun

* missed one

* refactor double field evaluation to inline fun

* spotless

* Apply suggestions from code review

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

* var -> val

Co-authored-by: Jake Wharton <github@jakewharton.com>
2021-12-26 16:05:55 -06:00
Zac Sweers
f3d2103ffb Convert Moshi.java to Kotlin (#1462)
* Rename .java to .kt

* Migrate Moshi.java to Moshi.kt

* Idiomatic cleanups

* Move comments down

* Apply suggestions from code review

Co-authored-by: Egor Andreevich <egor@squareup.com>

* Small little cleanups

Co-authored-by: Egor Andreevich <egor@squareup.com>
2021-12-26 15:49:52 -06:00
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