-
Notifications
You must be signed in to change notification settings - Fork 2k
[Management] Sending Raw Json
Rujun Chen edited this page Aug 20, 2021
·
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);
- Frequently Asked Questions
- Azure Identity Examples
- Configuration
- Performance Tuning
- Android Support
- Unit Testing
- Test Proxy Migration
- Azure Json Migration
- New Checkstyle and Spotbugs pattern migration
- Protocol Methods
- TypeSpec-Java Quickstart
- Getting Started Guidance
- Adding a Module
- Building
- Writing Performance Tests
- Working with AutoRest
- Deprecation
- BOM guidelines
- Release process
- Access helpers