-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Binarydata api update - Default json serializer #16319
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
Binarydata api update - Default json serializer #16319
Conversation
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
JonathanGiles
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JavaDocs need a pass over to be made more clear.
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
| * | ||
| * @see JsonSerializer | ||
| */ | ||
| public static BinaryData fromObject(Object data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given this API is converting into JSON we may want to call it fromObjectJson.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change it, we need to sync with .Net. I copied this API name from them.
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
| * @param <T> Generic type that the data is deserialized into. | ||
| * @return The {@link Object} of given type after deserializing the bytes. | ||
| */ | ||
| public <T> T toObject(Class<T> clazz) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename this API to something JSON specific? toJsonObject?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might force us, in future, to add other API for other formats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JsonObject has a different meaning. So, I think toObject() is fine as we will return a strongly-typed user-defined object here.
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Show resolved
Hide resolved
...rimental/src/samples/java/com/azure/core/experimental/util/BinaryDateJavaDocCodeSnippet.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Show resolved
Hide resolved
| * can be created from {@link InputStream}, {@link Flux} of {@link ByteBuffer}, {@link String}, {@link Object} and byte | ||
| * array. The data is collected from provided sources and stored into a byte array. | ||
| * This class is an abstraction over many different ways that binary data can be represented. The data represented by | ||
| * {@link BinaryData} is immutable. The {@link BinaryData} can be created from {@link InputStream}, {@link Flux} of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The data represented by {@link BinaryData} is immutable" is an odd statement to make? It is taken into BinaryData and presumably copied, but when given back to the user is mutable again. Perhaps clarify what you mean by this statement.
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Show resolved
Hide resolved
| } catch (IOException ex) { | ||
| throw LOGGER.logExceptionAsError(new UncheckedIOException(ex)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we not able to handle this in a more efficient manner? As it stands this means that the entire input stream is read into a buffer, converted into a byte array, and then copied into a new byte array? At the very least you can avoid the byte array copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the last byte array and same optimization in other from..() API as well.
| /** | ||
| * Serialize the given {@link Object} into {@link BinaryData} using json serializer which is available on classpath. | ||
| * The serializer on classpath must implement {@link JsonSerializer} interface. If the given Object is {@code null}, | ||
| * an empty {@link BinaryData} will be returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This documentation should link through an aka.ms link to the appropriate json serializer documentation (which will soon move to docs.microsoft.com, which is why in the meanwhile we will use an aka.ms link)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this link https://aka.ms/azsdk/java/wiki/serialization
JonathanGiles
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep iterating over the javadoc to fix typos, make messaging clearer, etc.
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Show resolved
Hide resolved
sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
Outdated
Show resolved
Hide resolved
JonathanGiles
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks better. I still think the JavaDoc could be improved to give more clarity around json serializer though.
|
/check-enforcer reset |
|
/check-enforcer run |
|
/check-enforcer evaluate |
API View : https://apiview.dev/Assemblies/Review/22274ac987a04a7589b6d5e6ee6b7554#com.azure.core.experimental.util.BinaryData