Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/core/azure-core-experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.0.0-beta.7 (Unreleased)

- Added : API `fromObject()` in `BinaryData` which uses `JsonSerializer` present in the classpath.

## 1.0.0-beta.6 (2020-10-06)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import com.azure.core.util.FluxUtil;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.serializer.JsonSerializerProviders;
import com.azure.core.util.serializer.ObjectSerializer;
import com.azure.core.util.serializer.JsonSerializer;
import com.azure.core.util.serializer.TypeReference;
import static com.azure.core.util.FluxUtil.monoError;

Expand Down Expand Up @@ -185,6 +187,25 @@ public static BinaryData fromBytes(byte[] data) {
return new BinaryData(data);
}

/**
* Serialize the given {@link Object} into {@link BinaryData} using the provided {@link JsonSerializer}. This will
Comment thread
hemanttanwar marked this conversation as resolved.
Outdated
* require the client to configure Json serializer in classpath.
*
* @param data The {@link Object} which needs to be serialized into bytes.
* @throws NullPointerException if {@code data} is null.
Comment thread
hemanttanwar marked this conversation as resolved.
Outdated
* @throws IllegalStateException If cannot find any JSON serializer provider on the classpath.
Comment thread
hemanttanwar marked this conversation as resolved.
Outdated
* @return {@link BinaryData} representing binary data. Or {@code null} if it fails to serialize the data.
Comment thread
hemanttanwar marked this conversation as resolved.
Outdated
*
* @see JsonSerializer
*/
public static BinaryData fromObject(Object data) {

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

Objects.requireNonNull(data, "'data' cannot be null.");
Comment thread
hemanttanwar marked this conversation as resolved.
Outdated

final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
JsonSerializerProviders.createInstance().serialize(outputStream, data);
Comment thread
alzimmermsft marked this conversation as resolved.
Outdated
return new BinaryData(outputStream.toByteArray());
}

/**
* Serialize the given {@link Object} into {@link BinaryData} using the provided {@link ObjectSerializer}.
*
Expand Down