Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.
This repository was archived by the owner on Jul 6, 2026. It is now read-only.

tsp, azure-json serialize on generic types #2629

Description

@weidongxu-microsoft

translate has payload being an array
https://github.com/Azure/azure-rest-api-specs/blob/main/specification/translation/Azure.AI.TextTranslation/routes.tsp#L61-L67
(request body and response body is both JSON array)

SDK generates

    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public List<TransliteratedText> transliterate(String language, String fromScript, String toScript,
        List<InputTextItem> requestBody) {
        // Generated convenience method for transliterateWithResponse
        RequestOptions requestOptions = new RequestOptions();
        return transliterateWithResponse(language, fromScript, toScript, BinaryData.fromObject(requestBody),
            requestOptions).getValue().toObject(TYPE_REFERENCE_LIST_TRANSLITERATED_TEXT);
    }

Serialization within BinaryData would go with Jackson (I assume due to type erasure). It should go with azure-json

Modify the code to

        return transliterateWithResponse(language, fromScript, toScript, BinaryData.fromObject(requestBody.stream().map(BinaryData::fromObject).collect(Collectors.toList())),
            requestOptions).getValue().toObject(TYPE_REFERENCE_LIST_TRANSLITERATED_TEXT);

would work for request body (however it still not desirable in codegen, as the generic type could be e.g. List<Map<List<Map<...>>>).
But the response body is hard to work with this pattern.


Kind of similar to Azure/azure-sdk-for-java#37793 (just Jackson vs azure-json, but both having similar problem of type erasure in generic type)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions