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

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

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

ObjectMapper.fromJson介绍

暂无

代码示例

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

/**
 * Parse a text representation of a JSON data structure
 *
 * @param text JSON text to parse
 * @return a data structure of lists and maps
 */
public Object parseText(String text) {
  if (text == null || text.length() == 0) {
    throw new IllegalArgumentException("The JSON input text should neither be null nor empty.");
  }
  return JsonFactory.create().fromJson ( text );
}

代码示例来源: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 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_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() {
  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 test_stringListProperty() {
  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_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_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_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 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 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);
}

相关文章