XmlMapper xmlMapper = new XmlMapper();
MyObject myObj = xmlMapper.readValue(xml, MyObject.class);
ObjectMapper jsonMapper = new ObjectMapper();
String json = jsonMapper.writeValueAsString(myObj);
System.out.println(json);
对于附件上传限制较高(> 130MB)的帐户,您需要使用" chunked"上传以上传您的文件。首先,通过执行以下操作注册您的分块上传:
答案 0 :(得分:1)
由于要添加工作项附件的文件是10MB(<130MB),因此您应该使用REST API作为u pload a text file而不是chunked upload REST API的方式。
以及将文件上传到VSTS并将文件添加为工作项附件的示例代码,如下所示:
int id=12;
string filename = @"C:\path\to\the\upload\file";
Uri accountUri = new Uri("https://account.visualstudio.com");
String personalAccessToken = "PAT";
VssConnection connection1 = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken));
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
Console.WriteLine("Attempting upload of: {0}", "");
AttachmentReference attachment = workItemTrackingClient.CreateAttachmentAsync(filename).Result;
Console.WriteLine(attachment.Id);
Console.WriteLine(attachment.Url);
BuildHttpClient buildClient = connection.GetClient<BuildHttpClient>();
WorkItemTrackingHttpClient workItemTrackingClient1 = connection.GetClient<WorkItemTrackingHttpClient>();
JsonPatchDocument patchDocument = new JsonPatchDocument
{
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/relations/-",
Value = new
{
rel = "AttachedFile",
url = attachment.Url,
attributes = new { comment = "VanDelay Industries - Spec" }
}
}
};
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result;
Console.WriteLine("succeed!");