union-type-wrappers

Add typed getters and setters over BinaryData properties for TypeSpec union types in Java models.

2.6k|2.2k|Updated Dec 6, 2011
One-click install
npx skills add https://github.com/Azure/azure-sdk-for-java --skill union-type-wrappers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: union-type-wrappers
Source: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/ai/.workflow_docs/union-type-wrappers
Command: npx skills add https://github.com/Azure/azure-sdk-for-java --skill union-type-wrappers

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses the challenge of accessing data within BinaryData fields in generated Java models when those fields represent TypeSpec union types, providing a more ergonomic and type-safe way to interact with them.

Core Features & Use Cases

  • Typed Getters and Setters: Replaces generic BinaryData accessors with specific methods for each union variant (e.g., getString(), getSomeModel(), setSomeModel(SomeModel value)).
  • Ergonomic Access: Simplifies interacting with union types, avoiding manual serialization/deserialization of BinaryData.
  • Use Case: When a generated Java model has a field like BinaryData myField that can be either a String or a MyModel object, this skill adds methods like getMyFieldAsString() and setMyField(MyModel value) for cleaner code.

Quick Start

Use the union-type-wrappers skill to add typed getters and setters for the BinaryData field 'myField' in the generated Java model.

Frequently Asked Questions about union-type-wrappers

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

FAQPage Schema
How do I get type-safe access to BinaryData union types in generated Java models?

You can get type-safe access to BinaryData union types by adding typed getters and setters for each union variant, such as getMyFieldAsString() or setMyField(MyModel value), directly over the BinaryData properties in your generated Java models.

Why does my generated Java SDK model use BinaryData instead of specific types for union fields?

Generated Java models use BinaryData for union fields because TypeSpec union types are codegen'd as BinaryData to accommodate multiple possible variants, requiring manual serialization without typed wrapper methods.

What's the best way to avoid manual serialization when working with BinaryData fields in Java SDKs?

The best way to avoid manual serialization of BinaryData fields is to apply typed wrapper methods that automatically handle conversion for supported union variants like string, primitive, Azure JsonSerializable, and Stainless types.

Does the union-type-wrappers approach support Azure JsonSerializable and Stainless types as union variants?

Yes, the union-type-wrappers approach supports string, primitive, Azure JsonSerializable, and Stainless types as union variants, adding specific accessor methods for each type over the underlying BinaryData property.

How do I add typed getters and setters for a BinaryData field representing a TypeSpec union type?

You add typed getters and setters by applying the union-type-wrappers skill to the target BinaryData field in the generated Java model, which generates variant-specific methods like getMyFieldAsString() for ergonomic and type-safe interaction.

Can I use typed accessors for BinaryData union fields in generated Java models without modifying the code generator?

Yes, you can use typed accessors without altering the core code generator by overlaying typed getters and setters onto the existing generated Java models to interact with BinaryData union fields type-safely.