Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.35k stars 1.99k forks source link

Error: property 'presetName' does not exist on type 'Microsoft.Media.Preset' #2251

Closed urbanspr1nter closed 4 years ago

urbanspr1nter commented 6 years ago

I am trying to create a Transform workflow and am getting an error while trying to invoke the call to create my Transform entity.

The error is complaining about not recognizing the property presetName... I have tried this both in the v2018_03_30 and v2018_06_01 API ... and am not finding luck :(

Caused by: com.microsoft.azure.management.mediaservices.v2018_06_01_preview.ApiErrorException: Status code 400, {
  "error": {
    "code": "InvalidResource",
    "message": "The property 'presetName' does not exist on type 'Microsoft.Media.Preset'. Make sure to only use property names that are defined by the type."
  }
}

Here is how I am creating my transform entity:

        List<TransformOutput> output = new LinkedList<>();

        Preset preset = new BuiltInStandardEncoderPreset()
                    .withPresetName(EncoderNamedPreset.ADAPTIVE_STREAMING);

        TransformOutput outputElement = new TransformOutput()
                .withPreset(preset);

        output.add(outputElement);

        TransformInner transformInner = new TransformInner()
                .withOutputs(output);

        result = this._mediaService.transforms().createOrUpdate(this._resourceGroupName, this._accountName, this.TransformName, transformInner);

        return result;

Looking at the code, it looks like the property is being defined correctly by the code generator, but is not passing validation upstream.

In addition, here is the request body:

{"properties":{"outputs":[{"preset":{"presetName":"AdaptiveStreaming","@odata":{"type":"#Microsoft.Media.BuiltInStandardEncoderPreset"}}}]}}
jalkanen commented 5 years ago

The FlatteningSerializer used in the Azure SDK serializes the "@odata.type" annotation as

{
    "@odata": {
         "type": "#Microsoft.Whatever"
     }
}

instead of

{
    "@odata.type": "#Microsoft.Whatever"
}

This is a bug in FlatteningSerializer, and can be fixed with the following patch:


diff --git a/client-runtime/src/main/java/com/microsoft/rest/serializer/FlatteningSerializer.java b/client-runtime/src/main/java/com/microsoft/rest/serializer/FlatteningSerializer.java
index 3b11f0a79..b83c8ff66 100644
--- a/client-runtime/src/main/java/com/microsoft/rest/serializer/FlatteningSerializer.java
+++ b/client-runtime/src/main/java/com/microsoft/rest/serializer/FlatteningSerializer.java
@@ -177,13 +177,14 @@ public class FlatteningSerializer extends StdSerializer<Object> implements Resol
                 ObjectNode node = resCurrent;
                 String key = field.getKey();
                 JsonNode outNode = resCurrent.get(key);
+
                 if (key.matches(".*[^\\\\]\\\\..+")) {
                     // Handle escaped map key
                     //
                     String originalKey = key.replaceAll("\\\\.", ".");
                     resCurrent.remove(key);
                     resCurrent.put(originalKey, outNode);
-                } else if (key.matches(".+[^\\\\]\\..+")) {
+                } else if (key.matches(".+[^\\\\]\\..+") && !key.equals("@odata.type") ) {
                     // Handle flattening properties
                     //
                     String[] values = key.split("((?<!\\\\))\\.");

I don't know if this is the right fix though, as it seems... hacky.

joshfree commented 5 years ago

@yungezz can you help route this?

yungezz commented 5 years ago

hi @yaohaizh could you pls take care of this java sdk generation issue?

yungezz commented 4 years ago

hi @xccc-msft could you pls have a look?

xseeseesee commented 4 years ago

@urbanspr1nter Are you still facing same issue? I just tried with v2018_07_01. It looks the serialize issue has been fixed. I'm able to get below:

{"properties":{"outputs":[{"preset":{"presetName":"AdaptiveStreaming","@odata.type":"#Microsoft.Media.BuiltInStandardEncoderPreset"}}]}}
yungezz commented 4 years ago

close the issue now since SDK with specific API version released already. feel free to create new issue if any other ask.