Skip to content

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

Description

@XiaofeiCao

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.

Metadata

Metadata

Assignees

Labels

Azure.Coreazure-coreMgmtThis issue is related to a management-plane library.

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions