You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using BinaryData with JSON merge patch it may be using it incorrectly. The following code is used:
StringvariableName = convenientParameterName + "InBinaryData";
javaBlock.line(String.format("JsonMergePatchHelper.get%1$sAccessor().prepareModelForJsonMergePatch(%2$s, true);", convenientParameterTypeName, convenientParameterName));
javaBlock.line(String.format("BinaryData %1$s = BinaryData.fromBytes(%2$s.toBytes());", variableName, expression)); // BinaryData.fromObject() will not fire serialization, use toBytes() to fire serializationjavaBlock.line(String.format("JsonMergePatchHelper.get%1$sAccessor().prepareModelForJsonMergePatch(%2$s, false);", convenientParameterTypeName, convenientParameterName));
returnvariableName;
We should be using the BinaryData.fromObject directly rather than converting it from Object to byte[] then landing on BinaryData. This may also result in BinaryData being used incorrectly later on as it loses type information and may result it being considered binary in JSON (base64 encoded string) rather than a JSON object.
Edit
After further investigation I've realized it is done this way as BinaryData.fromObject doesn't serialize the object until the BinaryData is queried. And serialization needs to be forced as the patch serialization status is only within this block of code. This should still on use BinaryData.fromObject but the created BinaryData should have something like getLength() called which will force serialization.
When using
BinaryDatawith JSON merge patch it may be using it incorrectly. The following code is used:https://github.com/Azure/autorest.java/blob/main/javagen/src/main/java/com/azure/autorest/template/ConvenienceMethodTemplateBase.java#L788
We should be using the
BinaryData.fromObjectdirectly rather than converting it fromObjecttobyte[]then landing onBinaryData. This may also result inBinaryDatabeing used incorrectly later on as it loses type information and may result it being considered binary in JSON (base64 encoded string) rather than a JSON object.Edit
After further investigation I've realized it is done this way as
BinaryData.fromObjectdoesn't serialize the object until theBinaryDatais queried. And serialization needs to be forced as the patch serialization status is only within this block of code. This should still on useBinaryData.fromObjectbut the createdBinaryDatashould have something likegetLength()called which will force serialization.