com.azure.cosmos.implementation.InternalObjectNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-cosmos Show documentation
Show all versions of azure-cosmos Show documentation
This Package contains Microsoft Azure Cosmos SDK (with Reactive Extension Reactor support) for Azure Cosmos DB SQL API
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.cosmos.implementation;
import com.azure.cosmos.BridgeInternal;
import com.azure.cosmos.CosmosItemSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;
public class InternalObjectNode extends Resource {
private static final ObjectMapper MAPPER = Utils.getSimpleObjectMapper();
/**
* Initialize an empty InternalObjectNode object.
*/
public InternalObjectNode() {
}
/**
* Initialize a InternalObjectNode object from json string.
*
* @param bytes the json string that represents the document object.
*/
public InternalObjectNode(byte[] bytes) {
super(bytes);
}
/**
* Initialize a InternalObjectNode object from json string.
*
* @param byteBuffer the json string that represents the document object.
*/
public InternalObjectNode(ByteBuffer byteBuffer) {
super(byteBuffer);
}
/**
* Sets the id
*
* @param id the name of the resource.
* @return the cosmos item properties with id set
*/
public InternalObjectNode setId(String id) {
super.setId(id);
return this;
}
/**
* Initialize a InternalObjectNode object from json string.
*
* @param jsonString the json string that represents the document object.
*/
public InternalObjectNode(String jsonString) {
super(jsonString);
}
public InternalObjectNode(ObjectNode propertyBag) {
super(propertyBag);
}
/**
* fromObjectToInternalObjectNode returns InternalObjectNode
*/
public static InternalObjectNode fromObjectToInternalObjectNode(Object cosmosItem) {
if (cosmosItem instanceof InternalObjectNode) {
return (InternalObjectNode) cosmosItem;
} else if (cosmosItem instanceof byte[]) {
return new InternalObjectNode((byte[]) cosmosItem);
} else if (cosmosItem instanceof ObjectNode) {
return new InternalObjectNode((ObjectNode) cosmosItem);
} else {
try {
return new InternalObjectNode(InternalObjectNode.MAPPER.writeValueAsString(cosmosItem));
} catch (IOException e) {
throw new IllegalArgumentException("Can't serialize the object into the json string", e);
}
}
}
/**
* fromObject returns Document for compatibility with V2 sdk
*/
public static Document fromObject(Object cosmosItem) {
Document typedItem;
if (cosmosItem instanceof InternalObjectNode) {
return new Document(((InternalObjectNode) cosmosItem).toJson());
} else if (cosmosItem instanceof byte[]) {
return new Document((byte[]) cosmosItem);
} else if (cosmosItem instanceof ObjectNode) {
return new Document((new InternalObjectNode((ObjectNode)cosmosItem)).toJson());
} else {
try {
return new Document(InternalObjectNode.MAPPER.writeValueAsString(cosmosItem));
} catch (IOException e) {
throw new IllegalArgumentException("Can't serialize the object into the json string", e);
}
}
}
public static ByteBuffer serializeJsonToByteBuffer(
Object cosmosItem,
CosmosItemSerializer itemSerializer,
String trackingId,
boolean isIdValidationEnabled) {
checkNotNull(itemSerializer, "Argument 'itemSerializer' must not be null.");
if (cosmosItem instanceof InternalObjectNode) {
InternalObjectNode internalObjectNode = ((InternalObjectNode) cosmosItem);
Consumer