Skip to content

Fix NPE when custom JsonAdapter (not nullSafe()) is registered via Supplier #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025

Conversation

rob-bygrave
Copy link
Contributor

@rob-bygrave rob-bygrave commented Mar 20, 2025

Fix in DJsonb by adding .nullSafe() for the Supplier<JsonAdapter<T>> case.

Example:

@CustomAdapter(global = false)
public class MoneySerializer2 implements JsonAdapter<BigDecimal> {

  /**  Default constructor -> registered via {@code Supplier<JsonAdapter>} */
  public MoneySerializer2() { }

  @Override
  public BigDecimal fromJson(JsonReader reader) {
    return reader.readDecimal().setScale(2, RoundingMode.DOWN);
  }

  @Override
  public void toJson(JsonWriter writer, BigDecimal value) {
    writer.value(value.setScale(2, RoundingMode.DOWN));
  }
}

Due to using the default constructor, this custom JsonAdapter is registered via Supplier<JsonAdapter<T>> and that wasn't getting the .nullSafe() wrapper.

…pplier

Fix in DJsonb by adding `.nullSafe()` for the `Supplier<JsonAdapter<T>>` case.
@rob-bygrave rob-bygrave requested a review from SentryMan March 20, 2025 00:51
@SentryMan SentryMan enabled auto-merge March 20, 2025 00:52
@rob-bygrave rob-bygrave added the bug Something isn't working label Mar 20, 2025
@SentryMan SentryMan added this to the 3.2 milestone Mar 20, 2025
@SentryMan SentryMan merged commit 56f31ed into main Mar 20, 2025
9 checks passed
@rob-bygrave rob-bygrave deleted the feature/npe-custom-serializer branch March 20, 2025 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants