Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Unreleased

* None yet.
* Keep `JsonAdapter`'s generic signature in the embedded R8 rules so `@ToJson` and `@FromJson` delegate parameters stay parameterized under R8 full mode.


## [2.0.0-alpha.1] - 2026-01-28
Expand Down
12 changes: 12 additions & 0 deletions moshi/src/main/resources/META-INF/proguard/moshi.pro
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@
@com.squareup.moshi.FromJson <methods>;
@com.squareup.moshi.ToJson <methods>;
}

# R8 full mode retains a generic signature only for types a keep rule matches. Matching
# JsonAdapter keeps JsonAdapter<T> on @ToJson/@FromJson methods that already reference it, so
# Method.getGenericParameterTypes() stays a ParameterizedType and bind() can read the delegate
# type argument. A raw JsonAdapter has no type argument to recover.
# allowshrinking still allows unused members to be removed, so this does not pin code into the
# app. allowobfuscation still allows the class to be renamed; parametersAreJsonAdapters compares
# rawType to JsonAdapter, and R8 rewrites both the library reference and the signature.
# The rule names this single class, with no member wildcard and no com.squareup.moshi.**
# pattern, so subclasses and other Moshi types stay unmatched. allowoptimization is omitted so
# the rule matches R8 full-mode signature guidance and Retrofit's retrofit2.Response rule.
-keep,allowobfuscation,allowshrinking class com.squareup.moshi.JsonAdapter
33 changes: 33 additions & 0 deletions moshi/src/test/java/com/squareup/moshi/MoshiProguardRulesTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2026 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.moshi

import com.google.common.truth.Truth.assertThat
import org.junit.Test

class MoshiProguardRulesTest {
@Test
fun jsonAdapterKeepRuleIsAnExactLine() {
val rules =
requireNotNull(javaClass.classLoader.getResource("META-INF/proguard/moshi.pro")) {
"Missing META-INF/proguard/moshi.pro"
}
.readText()
// Exact line: a member wildcard or a com.squareup.moshi.** pattern must not match.
assertThat(rules.lines())
.contains("-keep,allowobfuscation,allowshrinking class com.squareup.moshi.JsonAdapter")
}
}