Java’s worse. In particular, Moshi+Java creates in...
# squarelibraries
j
Java’s worse. In particular, Moshi+Java creates instances without constructors which creates the opportunities for really surprising code.
Copy code
class Payment {
  String currency = "USD";
  long amount;

  public Payment(long amount) {
    this.amount = amount;
  }
}
Moshi decodes
{"amount": 100}
to a
Payment
with a
null
currency! We’re doing nasty things because Moshi works field-by-field and there’s no nice way to map field names to constructor parameter names.
mind blown 2