jodd.json.JsonSerializer.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(141)

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

JsonSerializer.<init>介绍

暂无

代码示例

代码示例来源:origin: oblac/jodd

@Test
void testCollection() {
  JsonSerializer serializer = new JsonSerializer();
  String colorsJson = serializer.serialize(colors.values());
  for (Object o : colors.entrySet()) {
    Map.Entry entry = (Map.Entry) o;
    assertAttributeMissing(entry.getKey().toString(), colorsJson);
    assertStringValue(entry.getValue().toString(), colorsJson);
  }
  assertTrue(colorsJson.startsWith("["));
  assertTrue(colorsJson.endsWith("]"));
}

代码示例来源:origin: oblac/jodd

@Test
void testSerializeCalendar() throws Exception {
  final Calendar input = Calendar.getInstance(TimeZone.getTimeZone("Europe/Berlin"), Locale.GERMANY);
  input.clear();
  input.setTimeInMillis(1512166354000L);
  final String expected_json = "1512166354000";
  final String actual_json = new JsonSerializer().serialize(input);
  // asserts
  assertNotNull(actual_json);
  assertEquals(expected_json, actual_json);
}

代码示例来源:origin: oblac/jodd

private void assertSerializedTo(String original, String expected) {
  JsonSerializer serializer = new JsonSerializer();
  String json = serializer.serialize(original);
  assertEquals(expected, json);
}

代码示例来源:origin: oblac/jodd

@Test
void testStrings() {
  String text = "Hello";
  String json = new JsonSerializer().serialize(new StringBuilder(text));
  assertEquals("\"Hello\"", json);
  json = new JsonSerializer().serialize(new StringBuffer(text));
  assertEquals("\"Hello\"", json);
}

代码示例来源:origin: oblac/jodd

@Test
void testChar() {
  Character character = Character.valueOf('J');
  String json = new JsonSerializer().serialize(character);
  assertEquals("\"J\"", json);
}

代码示例来源:origin: oblac/jodd

@Test
void testClass() {
  String json = new JsonSerializer().serialize(JsonSerializerTest.class);
  assertEquals("\"" + JsonSerializerTest.class.getName() + "\"", json);
}

代码示例来源:origin: oblac/jodd

@Test
void testGeneralMapDeserialization2() {
  JsonParsers.forEachParser(jsonParser -> {
    String json = new JsonSerializer().serialize(creator.createJodder());
    Map<String, Object> deserialized = jsonParser.parse(json);
    assertEquals("Igor", deserialized.get("firstname"));
    assertEquals("Spasic", deserialized.get("lastname"));
    assertTrue(Map.class.isAssignableFrom(deserialized.get("work").getClass()));
    assertTrue(Map.class.isAssignableFrom(deserialized.get("home").getClass()));
  });
}

代码示例来源:origin: oblac/jodd

@Test
void testCopyOnWriteList() {
  CopyOnWriteArrayList<Person> people = new CopyOnWriteArrayList<>();
  people.add(jodder);
  people.add(modesty);
  String json = new JsonSerializer().serialize(people);
  assertAttribute("firstname", json);
  assertStringValue("Igor", json);
  assertStringValue("Modesty", json);
}

代码示例来源:origin: oblac/jodd

@Test
void testExcludeAll() {
  JsonSerializer serializer = new JsonSerializer();
  String json = serializer.exclude("*").serialize(jodder);
  assertEquals("{}", json);
}

代码示例来源:origin: oblac/jodd

@Test
void testDeserializeWithIncludes() {
  JsonParsers.forEachParser(jsonParser -> {
    Person igor = creator.createJodder();
    String json = new JsonSerializer().include("phones", "hobbies").serialize(igor);
    Person jsonIgor = jsonParser.parse(json, Person.class);
    assertEquals(2, jsonIgor.getPhones().size());
    assertEquals(0, jsonIgor.getHobbies().size());
  });
}

代码示例来源:origin: oblac/jodd

@Test
void testDates() {
  JsonSerializer serializer = new JsonSerializer();
  String peopleJson = serializer.exclude("home", "work").serialize(jodder);
  assertAttribute("firstname", peopleJson);
  assertStringValue("Igor", peopleJson);
  assertNumber(jodder.getBirthdate().getTime(), peopleJson);
  assertStringValueMissing("java.util.Date", peopleJson);
}

代码示例来源:origin: oblac/jodd

@Test
void testCircularDependenciesArray() {
  WhiteBar[] whiteBars = new WhiteBar[1];
  WhiteBar white = new WhiteBar();
  white.setSum(1);
  white.setBars(whiteBars);
  whiteBars[0] = white;
  String json = new JsonSerializer().serialize(whiteBars);
  assertEquals("[{\"sum\":1}]", json);
}

代码示例来源:origin: oblac/jodd

@Test
void testSerializeSuperClass() {
  JsonSerializer serializer = new JsonSerializer();
  String json = serializer.serialize(dilbert);
  assertAttribute("company", json);
  assertStringValue("Initech", json);
  assertAttribute("firstname", json);
  assertStringValue("Dilbert", json);
}

代码示例来源:origin: oblac/jodd

@Test
void testSettersWithoutGettersAreMissing() {
  Friend friend = new Friend("Nugget", "Donkey Rider", "Slim");
  String json = new JsonSerializer().include("*").serialize(friend);
  assertAttribute("nicknames", json);
  assertAttributeMissing("nicknamesAsArray", json);
}

代码示例来源:origin: oblac/jodd

@Test
void testPoint() {
  JsonParser.Defaults.classMetadataName = "__class";
  JsonSerializer.Defaults.classMetadataName = "__class";
  JsonParsers.forEachParser(jsonParser -> {
    String json = new JsonSerializer().serialize(new Point2D.Float(1.0f, 2.0f));
    Point2D.Float point = jsonParser.parse(json);
    assertEquals(1.0f, point.x, DELTA);
    assertEquals(2.0f, point.y, DELTA);
  });
}

代码示例来源:origin: oblac/jodd

@Test
void testWildcards() {
  JsonSerializer.Defaults.classMetadataName = "class";
  JsonSerializer serializer = new JsonSerializer();
  String json = serializer.include("phones").exclude("*.class").serialize(jodder);
  assertAttributeMissing("class", json);
  assertAttribute("phones", json);
  assertAttributeMissing("hobbies", json);
}

代码示例来源:origin: oblac/jodd

@Test
void testDeepSerializationCycles() {
  JsonSerializer serializer = new JsonSerializer();
  String json = serializer.deep(true).serialize(people);
  assertAttribute("zipcode", json);
  assertEquals(2, occurs(pedroZip.getZipcode(), json));
  assertAttributeMissing("person", json);
}

代码示例来源:origin: oblac/jodd

@Test
void testDeserializeInterfaces() {
  JsonParsers.forEachParser(jsonParser -> {
    Hero superman = creator.createSuperman();
    String json = new JsonSerializer().include("powers").setClassMetadataName("class").serialize(superman);
    Hero jsonSuperMan = jsonParser.setClassMetadataName("class").parse(json, Hero.class);
    assertNotNull(jsonSuperMan);
    assertEquals(4, jsonSuperMan.getPowers().size());
    assertHeroHasSuperPowers(jsonSuperMan);
  });
}

代码示例来源:origin: oblac/jodd

@Test
void testDeepSerializationWithIncludeOverrides() {
  JsonSerializer serializer = new JsonSerializer();
  String peopleJson = serializer.include("people.hobbies").deep(true).serialize(network);
  assertAttribute("firstname", peopleJson);
  assertStringValue("Igor", peopleJson);
  assertAttribute("hobbies", peopleJson);
  assertStringValue("read", peopleJson);
  assertStringValue("run", peopleJson);
  assertStringValue("code", peopleJson);
}

代码示例来源:origin: oblac/jodd

@Test
void testSetIncludes() {
  JsonSerializer serializer = new JsonSerializer();
  serializer.include("people.hobbies", "phones", "home", "people.resume");
  assertEquals(4, serializer.rules.totalRules());
  assertEquals("[people.hobbies]", serializer.rules.getRule(0).toString());
  assertEquals("[phones]", serializer.rules.getRule(1).toString());
  assertEquals("[home]", serializer.rules.getRule(2).toString());
  assertEquals("[people.resume]", serializer.rules.getRule(3).toString());
}

相关文章