Skip to content

Conversation

@hemanttanwar
Copy link
Contributor

@hemanttanwar hemanttanwar commented Oct 14, 2020

@ghost ghost added the Azure.Core azure-core label Oct 14, 2020
Copy link
Member

@JonathanGiles JonathanGiles left a 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.

*
* @see JsonSerializer
*/
public static BinaryData fromObject(Object data) {
Copy link
Member

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.

Copy link
Contributor Author

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.

* @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) {
Copy link
Member

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?

@JonathanGiles @srnagar

Copy link
Contributor Author

@hemanttanwar hemanttanwar Oct 21, 2020

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.

Copy link
Member

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.

* 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
Copy link
Member

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.

} catch (IOException ex) {
throw LOGGER.logExceptionAsError(new UncheckedIOException(ex));
}
}
Copy link
Member

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.

Copy link
Contributor Author

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.
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@JonathanGiles JonathanGiles left a 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.

Copy link
Member

@JonathanGiles JonathanGiles left a 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.

@hemanttanwar
Copy link
Contributor Author

/check-enforcer reset

@hemanttanwar
Copy link
Contributor Author

/check-enforcer run

@hemanttanwar
Copy link
Contributor Author

/check-enforcer evaluate

@hemanttanwar hemanttanwar merged commit 8928a8d into Azure:master Oct 23, 2020
@hemanttanwar hemanttanwar deleted the binarydata-api-update branch October 23, 2020 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure.Core azure-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants