Skip to content
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

[FEATURE REQ] mgmt azure-json, SubResource need to implement JsonSerializable interface #40047

Closed
Tracked by #38333
XiaofeiCao opened this issue May 6, 2024 · 0 comments · Fixed by #40076
Closed
Tracked by #38333
Assignees
Labels
Azure.Core azure-core Mgmt This issue is related to a management-plane library.

Comments

@XiaofeiCao
Copy link
Contributor

XiaofeiCao commented May 6, 2024

We have classes that contains SubResource. When stream-style-serialization is enabled for mgmt, it'll cause compilation error, due to it not implementing JsonSerializable.

@Fluent
public final class AvailabilitySetProperties implements JsonSerializable<AvailabilitySetProperties> {
  private SubResource proximityPlacementGroup;

 @Override
  public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
      jsonWriter.writeStartObject();
      // compilation error, jsonWriter.writeJsonField expects JsonSerializable
      jsonWriter.writeJsonField("proximityPlacementGroup", this.proximityPlacementGroup);
      return jsonWriter.writeEndObject();
  }

 public static AvailabilitySetProperties fromJson(JsonReader jsonReader) throws IOException {
      return jsonReader.readObject(reader -> {
          AvailabilitySetProperties deserializedAvailabilitySetProperties = new AvailabilitySetProperties();
          while (reader.nextToken() != JsonToken.END_OBJECT) {
              String fieldName = reader.getFieldName();
              reader.nextToken();
  
              if ("proximityPlacementGroup".equals(fieldName)) {
                  // compilation error, SubResource doesn't have a `fromJson` method
                  deserializedAvailabilitySetProperties.proximityPlacementGroup = SubResource.fromJson(reader);
              } else {
                  reader.skipChildren();
              }
          }
  
          return deserializedAvailabilitySetProperties;
      });
  }
}

We need SubResource to implement JsonSerializable and a proper fromJson method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core azure-core Mgmt This issue is related to a management-plane library.
Projects
Status: Done
1 participant