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

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

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

JsonSerializer.deep介绍

[英]Defines if collections should be followed, i.e. to perform deep serialization.
[中]定义是否应遵循集合,即执行深度序列化。

代码示例

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

/**
 * Returns JSON serialized by default {@link JsonSerializer}.
 */
@Override
public String toString() {
  return JsonSerializer.create().deep(true).serialize(map);
}

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

@Override
public String toString() {
  return JsonSerializer.create().deep(true).serialize(this);
}

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

/**
 * Creates a JSON response from an exception. Response body will have information about the
 * exception and response status will be set to 500.
 */
public static JsonResult of(final Exception exception) {
  final HashMap<String, Object> errorMap = new HashMap<>();
  errorMap.put("message", ExceptionUtil.message(exception));
  errorMap.put("error", exception.getClass().getName());
  errorMap.put("cause", exception.getCause() != null ? exception.getCause().getClass().getName() : null);
  final ArrayList<String> details = new ArrayList<>();
  final StackTraceElement[] ste = ExceptionUtil.getStackTrace(exception, null, null);
  for (StackTraceElement stackTraceElement : ste) {
    details.add(stackTraceElement.toString());
  }
  errorMap.put("details", details);
  final String json = JsonSerializer.create().deep(true).serialize(errorMap);
  return new JsonResult(json).status(HttpStatus.error500().internalError());
}

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

/**
 * Creates JSON result from given object. The object will be serialized to JSON.
 */
public static JsonResult of(final Object object) {
  final String json = JsonSerializer.create().deep(true).serialize(object);
  return new JsonResult(json);
}

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

json = JsonSerializer.create().deep(true).serialize(resultValue);
status = 200;
statusMessage = "OK";

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

/**
 * Encodes the {@link SimTok} to JSON string.
 */
public String encode(final SimTok simTok) {
  final String json = JsonSerializer.create().deep(true).serialize(simTok);
  final String p1 = Base64.encodeToString("JoddSimTok" + SALT_ROUNDS);
  final String p2 = Base64.encodeToString(json);
  final String salt = BCrypt.gensalt(SALT_ROUNDS);
  final String p3 = BCrypt.hashpw(p1 + "." + p2 + "." + SECRET, salt);
  return p1 + "." + p2 + "." + p3;
}

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

@Test
void testSerializeSets() {
  HitList hitList = new HitList();
  hitList.setNames(new HashSet<>());
  hitList.getNames().add("Joe");
  hitList.getNames().add("Pig");
  hitList.setNumbers(new HashSet<>());
  hitList.getNumbers().add(173);
  hitList.getNumbers().add(22);
  String json = JsonSerializer
    .create()
    .deep(true)
    .serialize(hitList);
  assertTrue(json.contains("\"names\""));
  assertTrue(json.contains("\"numbers\""));
  assertTrue(json.contains("\"Pig\""));
  assertTrue(json.contains("\"Joe\""));
  assertTrue(json.contains("173"));
  assertTrue(json.contains("22"));
}

代码示例来源: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 testParseSerializeCatalog() {
  JsonParsers.forEachParser(jsonParser -> {
    String json = loadJSON("citm_catalog");
    Catalog catalog = jsonParser.parse(json, Catalog.class);
    String newJson = new JsonSerializer().deep(true).serialize(catalog);
    Catalog jsonCatalog = jsonParser.parse(newJson, Catalog.class);
    assertCatalog(jsonCatalog);
  });
}

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

@Test
void testDeepSerializationWithExcludes() {
  JsonSerializer serializer = new JsonSerializer();
  String peopleJson = serializer.exclude("people.work").deep(true).serialize(network);
  assertAttribute("firstname", peopleJson);
  assertStringValue("Igor", peopleJson);
  assertAttributeMissing("work", peopleJson);
  assertStringValue("173 Hackers Drive", peopleJson);
  assertAttribute("home", peopleJson);
  assertAttribute("phones", peopleJson);
}

代码示例来源: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 testCircularDependency_none() {
  JsonParsers.forEachParser(jsonParser -> {
    A a1 = new A();
    a1.setName("a1");
    A a2 = new A();
    a2.setName("a2");
    B b = new B();
    b.setProp("value");
    b.setA(a2);        // b -> a2, no circ.dep.
    // circular reference
    a1.setPi(b);
    JsonSerializer serializer = new JsonSerializer().deep(true);
    String json = serializer.serialize(a1);
    jsonParser.parse(json);
    assertTrue(json.contains("a1"));
    assertTrue(json.contains("a2"));
  });
}

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

@Test
void testDeepSerialization() {
  JsonSerializer serializer = new JsonSerializer();
  String peopleJson = serializer.deep(true).serialize(network);
  assertAttribute("name", peopleJson);
  assertStringValue("My Network", peopleJson);
  assertAttribute("firstname", peopleJson);
  assertStringValue("Igor", peopleJson);
  assertStringValue("Modesty", peopleJson);
  assertAttribute("lastname", peopleJson);
  assertStringValue("Spasic", peopleJson);
  assertAttributeMissing("hobbies", peopleJson); // annotation explicitly excludes this
  assertStringValueMissing("read", peopleJson);
}

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

@Test
void testParseCatalogAsMap() {
  JsonParsers.forEachParser(jsonParser -> {
    String json = loadJSON("citm_catalog");
    Map catalog = jsonParser
      .map("values.keys", Long.class)
      .map("venueNames.keys", String.class)
      .useAltPaths()
      .parse(json);
    String newJson = new JsonSerializer().deep(true).serialize(catalog);
    Catalog jsonCatalog = jsonParser.parse(newJson, Catalog.class);
    assertCatalog(jsonCatalog);
  });
}

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

@Test
void testCircularDependency_property() {
  JsonParsers.forEachParser(jsonParser -> {
    A a1 = new A();
    a1.setName("a1");
    A a2 = new A();
    a2.setName("a2");
    B b = new B();
    b.setProp("value");
    b.setA(a1);        // b -> a1, has circ.dep.
    // circular reference
    a1.setPi(b);
    JsonSerializer serializer = new JsonSerializer().deep(true);
    String json = serializer.serialize(a1);
    jsonParser.parse(json);
    assertEquals(1, StringUtil.count(json, "a1"));
    assertEquals(0, StringUtil.count(json, "a2"));
    assertEquals(1, StringUtil.count(json, "pi"));
  });
}

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

@Test
  void testCircularDependency_propertyArray() {
    JsonParsers.forEachParser(jsonParser -> {
      A a1 = new A();
      a1.setName("a1");

      A a2 = new A();
      a2.setName("a2");

      B b = new B();
      b.setProp("value");
      b.setA(a1);        // b -> a1, has circ.dep.

      b.addP(a1);
      b.addP(a2);

      // circular reference
      a1.setPi(b);

      JsonSerializer serializer = new JsonSerializer().deep(true);

      String json = serializer.serialize(a1);
      jsonParser.parse(json);

      assertEquals(1, StringUtil.count(json, "a1"));
      assertEquals(1, StringUtil.count(json, "a2"));
    });
  }
}

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

@Test
void testParseSerializeCatalogNotDeep() {
  JsonParsers.forEachParser(jsonParser -> {
    String json = loadJSON("citm_catalog");
    Catalog catalog = jsonParser.parse(json, Catalog.class);
    String newJson = new JsonSerializer().deep(false).serialize(catalog);
    Catalog jsonCatalog = jsonParser.parse(newJson, Catalog.class);
    assertNull(jsonCatalog.getPerformances());
    assertNull(jsonCatalog.getAreaNames());
    assertNull(jsonCatalog.getEvents());
    assertNull(jsonCatalog.getAudienceSubCategoryNames());
    assertNull(jsonCatalog.getSeatCategoryNames());
    assertNull(jsonCatalog.getSubTopicNames());
    assertNull(jsonCatalog.getTopicNames());
    assertNull(jsonCatalog.getTopicSubTopics());
    assertNull(jsonCatalog.getVenueNames());
  });
}

代码示例来源:origin: com.liferay.launchpad/serializer-json-jodd

@Override
public String serialize(Object object, boolean deep) {
  return new JsonSerializer().deep(deep).serialize(object);
}

代码示例来源:origin: com.liferay.launchpad/api-client

@Override
public String serialize(Object object, boolean deep) {
  return JsonSerializer
    .create()
    .deep(deep)
    .use(PodMultiMap.class, POD_MULTI_MAP_JSON_SERIALIZER)
    .use(long.class, LONG_TO_STRING_JSON_SERIALIZER)
    .use(Long.class, LONG_TO_STRING_JSON_SERIALIZER)
    .serialize(object);
}

代码示例来源:origin: org.jodd/jodd-joy

/**
 * Encodes the {@link SimTok} to JSON string.
 */
public String encode(final SimTok simTok) {
  final String json = JsonSerializer.create().deep(true).serialize(simTok);
  final String p1 = Base64.encodeToString("JoddSimTok" + SALT_ROUNDS);
  final String p2 = Base64.encodeToString(json);
  final String salt = BCrypt.gensalt(SALT_ROUNDS);
  final String p3 = BCrypt.hashpw(p1 + "." + p2 + "." + SECRET, salt);
  return p1 + "." + p2 + "." + p3;
}

相关文章