如何从杰克逊ObjectMapper中获取JSON

时间:2019-05-22 20:36:49

标签: json jackson

我们需要构建一个json负载以发送到剩余端点。我们的组织使用Jackson。构建json的唯一方法(不创建数十个嵌套的空pojos)如下:

$ cat t471.cu
#include <thrust/copy.h>
#include <thrust/reduce.h>
#include <thrust/device_vector.h>
#include <thrust/iterator/permutation_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/iterator/counting_iterator.h>
#include <iostream>

using namespace thrust::placeholders;

int main(){

  int data[] = {1,2,3,4,5,6,7,8,9};
  int stencil[] = {1,0,1};
  int ds = sizeof(data)/sizeof(data[0]);
  int ss = sizeof(stencil)/sizeof(stencil[0]);
  int N = ds/ss;  // assume this whole number divisible

  thrust::device_vector<int> d_data(data, data+ds);
  thrust::device_vector<int> d_stencil(stencil, stencil+ss);
  int rs = thrust::reduce(d_stencil.begin(), d_stencil.end())*N;
  thrust::device_vector<int> d_result(rs);
  thrust::copy_if(d_data.begin(), d_data.end(), thrust::make_permutation_iterator(d_stencil.begin(), thrust::make_transform_iterator(thrust::counting_iterator<int>(0), _1 / N)), d_result.begin(), _1 == 1) - d_result.begin();
  thrust::copy_n(d_result.begin(), rs, std::ostream_iterator<int>(std::cout, ","));
  std::cout << std::endl;
  return 0;
}
$ nvcc -o t471 t471.cu
$ ./t471
1,2,3,7,8,9,
$

好,所以现在我在映射器中有一个复杂的json对象。我怎么弄出来的? 例如。如何从其中获取适合作为后负载发送到REST api的json字符串?

有许多设置漂亮打印的示例,但是这些示例围绕json单个Java对象(我没有做)或输出到流或文件(而不是简单的String)上进行。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

也许使用ObjectMapper.writeValueAsString


var user_name = "Arya Stark"
  GmailApp.sendEmail('dev@mycompany.com','QUOTE REQUEST','',{htmlBody:htmlBody,replyTo: replyto, 'from':user_name});