Conversation
# Conflicts: # kotlin/reflect/src/main/java/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapter.kt
|
At a glance, it feels like ClassJsonAdapter is the one that should be fixed to preserve insertion order. We also preserve insertion order in the standard map adapter. Curious for thoughts from @swankjesse and @JakeWharton on this |
|
I don't like that ClassJsonAdapter needs to sort fields either; I think we do that for determinism across JVMs. Retaining field order seems like the nicest user interface. Also note that fixing this would be very invasive to anyone upgrading. |
|
Original PR that sorted Java classes: |
|
Do we try to offer an system prop opt-out temporarily to ease migration (kinda like what coroutines does)? |
ZacSweers
left a comment
There was a problem hiding this comment.
Let's do this in ClassJsonAdapter as well and add a system property to restore the previous behavior as an escape hatch for people that need it. @hardwil would you be up for doing that? If not I can continue this work too
This change is replacing
LinkedHashMapwithTreeMapinKotlinJsonAdapterto match the ordering in theClassJsonAdapter, so that both Java and Kotlin instances will have ordering parity.When migrating code from Java to Kotlin, I found that some tests failed due to entry ordering changes between the respective adapters.