forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Sending Raw Json
Jianghao Lu edited this page Feb 24, 2016
·
1 revision
Be cautious whenever you are about to pass a JSON string as a parameter into a method that accepts that string as a Java Object
. Azure SDK expects a parsed JSON object to be passed in instead.
For example, the following method
// In DeploymentsOperations.java
ServiceResponse<DeploymentExtended> createOrUpdate(
String resourceGroupName,
String deploymentName,
Deployment parameters)
throws CloudException, IOException, IllegalArgumentException, InterruptedException;
asks for a Deployment
object, which contains DeploymentProperties
. The definition of DeploymentProperties
is:
public class DeploymentProperties {
/**
* Gets or sets the template content. Use only one of Template or
* TemplateLink.
*/
private Object template;
/**
* Gets or sets the URI referencing the template. Use only one of Template
* or TemplateLink.
*/
private TemplateLink templateLink;
// etc
}
If you do
DeploymentProperties properties = new DeploymentProperties();
properties.setTemplate(readTemplateJson());
Deployment deployment = new Deployment();
deployment.setProperties(properties);
client.getDeploymentsOperations().createOrUpdate(rgName, deploymentName, deployment);
Azure SDK for Java will send a JSON string, which is wrapped in escaped quotes. The server will not be able to handle it.
The correct way of creating a deployment:
DeploymentProperties properties = new DeploymentProperties()
properties.setTemplate(client.getMapperAdapter().getObjectMapper().readTree(readTemplateJson()));
Deployment deployment = new Deployment();
deployment.setProperties(properties);
client.getDeploymentsOperations().createOrUpdate(rgName, deploymentName, deployment);
Azure SDK for Java
- Overview
- Getting Started
- Logging
- ListOperationCallback
- Exception handling
- Sending raw JSON
- Migration from 0.9.x to 1.0
- Long Running Operations
Azure SDK for Java (Classic)