android-api-dto-safety

Harden Android Kotlin API DTOs and mappers for nullability and contract safety.

Updated Mar 5, 2026
One-click install
npx skills add https://github.com/Envy-7z/mobile-agent-skillpack --skill android-api-dto-safety
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: android-api-dto-safety
Source: https://github.com/Envy-7z/mobile-agent-skillpack/tree/main/skills/android-api-dto-safety
Command: npx skills add https://github.com/Envy-7z/mobile-agent-skillpack --skill android-api-dto-safety

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses issues with Android Kotlin API Data Transfer Objects (DTOs) and their mapping, specifically focusing on nullability and contract safety to prevent runtime errors like NullPointerExceptions (NPEs) and parsing failures.

Core Features & Use Cases

  • DTO Hardening: Improves the robustness of DTOs used with libraries like Retrofit, Moshi, or Gson.
  • Nullability Safety: Ensures DTO fields correctly handle null values, preventing NPEs.
  • Contract Adherence: Verifies that DTOs accurately reflect the API's contract, minimizing parsing errors for 4xx/5xx responses.
  • Use Case: When an API response changes slightly, causing your app to crash due to unexpected nulls or missing fields in your Kotlin DTOs, this skill helps you safely adjust the DTOs and mappers to match the new contract without breaking existing functionality.

Quick Start

Safely adjust the Kotlin DTOs and mappers for the user API to handle potential null values in the 'address' field.

Frequently Asked Questions about android-api-dto-safety

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent NullPointerExceptions when parsing API responses in Kotlin?

Prevent NullPointerExceptions when parsing API responses by hardening Kotlin DTOs with safe nullability defaults. Adjusting DTO fields and mappers to handle unexpected nulls avoids runtime crashes without altering the backend contract.

How do I safely adjust Kotlin DTOs when an API response changes?

Safely adjust Kotlin DTOs by updating field nullability and mapper logic to match the new API contract. This local modification prevents parsing errors and app crashes while maintaining existing functionality and avoiding non-null assertions.

Does this approach to DTO safety work with Retrofit, Moshi, and Gson?

Yes, this DTO safety approach works with Retrofit, Moshi, and Gson. It enhances Android Kotlin API data transfer objects and their mapping logic to improve nullability and contract safety across these specific parsing libraries.

Why does my Android app crash when an API returns missing fields?

Your Android app crashes from missing API fields because Kotlin DTOs likely use non-null assertions that fail during parsing. Replacing these assertions with safe defaults and nullable fields in your DTOs prevents such runtime crashes.

What is the best way to handle mismatched fields in Android API DTOs?

The best way to handle mismatched fields in Android API DTOs is to verify contract adherence and update mappers locally. Preferring safe defaults over non-null assertions ensures parsing errors for 4xx or 5xx responses are minimized.

When should I not use non-null assertions in Kotlin API DTOs?

You should not use non-null assertions in Kotlin API DTOs when an API response might change or omit fields. Relying on safe defaults and proper nullability handling prevents unexpected parsing failures and runtime NPEs.