org.boon.json.ObjectMapper.toJson()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(199)

本文整理了Java中org.boon.json.ObjectMapper.toJson()方法的一些代码示例,展示了ObjectMapper.toJson()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectMapper.toJson()方法的具体详情如下:
包路径:org.boon.json.ObjectMapper
类名称:ObjectMapper
方法名:toJson

ObjectMapper.toJson介绍

暂无

代码示例

代码示例来源:origin: json-path/JsonPath

public Result runBoon() {
  String result = null;
  String error = null;
  long time;
  Iterator<Object> query = null;
  long now = System.currentTimeMillis();
  try {
    if (!optionAsValues) {
      throw new UnsupportedOperationException("Not supported!");
    }
    io.gatling.jsonpath.JsonPath jsonPath = JsonPath$.MODULE$.compile(path).right().get();
    JsonParser jsonParser = new JsonParserCharArray();
    Object jsonModel = jsonParser.parse(json);
    query = jsonPath.query(jsonModel);
  } catch (Exception e) {
    error = getError(e);
  } finally {
    time = System.currentTimeMillis() - now;
    if (query != null) {
      List<Object> res = new ArrayList<Object>();
      while (query.hasNext()) {
        res.add(query.next());
      }
      ObjectMapper mapper = new ObjectMapperImpl();
      result = mapper.toJson(res);
    }
    return new Result("boon", time, result, error);
  }
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public void toJson(Object value, Writer writer) {
  this.objectMapper.toJson(value, writer);
}

代码示例来源:origin: boonproject/boon

@Test
public void test() {
  ObjectMapper mapper = JsonFactory.create(new JsonParserFactory(),
      new JsonSerializerFactory().setSerializeMapKeys(true).setEncodeStrings(true));
  HashMap<String, Object> data = new HashMap<>();
  data.put("\"hi\"", Double.parseDouble("1.2312312"));
  assertEquals("{\"\\\"hi\\\"\":1.2312312}", mapper.toJson(data));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_caseInsensitiveProperty_normal() {
  String json = "{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_stringArrayProperty_fromSingleValue() {
  String json = "{\"typeName\":\"Processes\",\"descriptions\":\"lala\"}";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"descriptions\":[\"lala\"]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void serializingClassFieldCausesSegFault() {
  SomeClass someClassInstance = new SomeClass(Bug287.class);
  ObjectMapper mapper = JsonFactory.create();
  final String json = mapper.toJson(someClassInstance);
  puts(json);
  SomeClass someClassInstance2 = mapper.readValue("{\"clazz\":\"org.boon.bugs.Bug287\"} ", SomeClass.class);
  ok = someClassInstance2.clazz.getName().equals("org.boon.bugs.Bug287");
}

代码示例来源:origin: boonproject/boon

@Test
public void test_caseInsensitiveProperty_lowercase() {
  String json = "{\"typename\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_caseInsensitiveProperty_uppercase() {
  String json = "{\"TYPENAME\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_listProperty() {
  String json = "{\"typeName\":\"Processes\",\"fields2\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields2\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_caseInsensitiveProperty_lowercase() {
  String json = "{\"typename\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_arrayProperty_fromSingleValue() {
  String json = "{\"typeName\":\"Processes\",\"fields\":{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_listProperty_fromSingleValue() {
  String json = "{\"typeName\":\"Processes\",\"fields2\":{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields2\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_stringListProperty_fromSingleValue() {
  String json = "{\"typeName\":\"Processes\",\"descriptions2\":\"lala\"} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"descriptions2\":[\"lala\"]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_caseInsensitiveProperty_lowercase() {
  String json = "{\"typename\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_caseInsensitiveProperty_normal() {
  String json = "{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_caseInsensitiveProperty_normal() {
  String json = "{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_caseInsensitiveProperty_uppercase() {
  String json = "{\"TYPENAME\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test_arrayProperty() {
  String json = "{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} ";
  ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class);
  puts(json);
  puts(objectMapper.toJson(map));
  assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}")));
}

代码示例来源:origin: boonproject/boon

@Test
public void test2() {
  user = new User("red", "yellow", "green", "purple");
  puts(user.getFavoriteColors());
  final ObjectMapper objectMapper = JsonFactory.createUseAnnotations(true);
  json = objectMapper.toJson(user);
  puts(json);
  user2 = objectMapper.fromJson(json, User.class);
  puts(user.getFavoriteColors());
  ok = user.equals(user2) || die("Users should be equal", user, user2);
}

代码示例来源:origin: boonproject/boon

public void test3() {
  user = new User("red", "yellow", "green", "purple");
  puts(user.getFavoriteColors());
  final JsonParserFactory jsonParserFactory = new JsonParserFactory().usePropertiesFirst().useAnnotations();
  final JsonSerializerFactory serializerFactory = new JsonSerializerFactory().includeNulls().useAnnotations();
  final ObjectMapper objectMapper = new ObjectMapperImpl(jsonParserFactory, serializerFactory);
  json = objectMapper.toJson(user);
  puts(json);
  user2 = objectMapper.fromJson(json, User.class);
  puts(user.getFavoriteColors());
  ok = user.equals(user2) || die("Users should be equal", user, user2);
}

相关文章