jodd.json.JsonParser.create()方法的使用及代码示例

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

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

JsonParser.create介绍

[英]Static ctor.
[中]静态选择器。

代码示例

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

  1. /**
  2. * Parses request body into the target type.
  3. */
  4. protected Object parseRequestBody(final String body, final Class targetType) {
  5. return JsonParser.create().parse(body, targetType);
  6. }

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

  1. @Test
  2. void testMergeInDepth0() {
  3. {
  4. JsonObject obj1 = JsonParser.create().parseAsJsonObject("{ \"foo\": { \"bar\": \"flurb\" }}");
  5. JsonObject obj2 = JsonParser.create().parseAsJsonObject("{ \"foo\": { \"bar\": \"eek\" }}");
  6. obj1.mergeIn(obj2, 0);
  7. assertEquals(1, obj1.size());
  8. assertEquals(1, obj1.getJsonObject("foo").size());
  9. assertEquals("flurb", obj1.getJsonObject("foo").getString("bar"));
  10. }
  11. {
  12. JsonObject obj1 = JsonParser.createLazyOne().parseAsJsonObject("{ \"foo\": { \"bar\": \"flurb\" }}");
  13. JsonObject obj2 = JsonParser.createLazyOne().parseAsJsonObject("{ \"foo\": { \"bar\": \"eek\" }}");
  14. obj1.mergeIn(obj2, 0);
  15. assertEquals(1, obj1.size());
  16. assertEquals(1, obj1.getJsonObject("foo").size());
  17. assertEquals("flurb", obj1.getJsonObject("foo").getString("bar"));
  18. }
  19. }

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

  1. /**
  2. * Decodes the String to the {@link SimTok}.
  3. * Returns {@code null} if decoded token is NOT valid.
  4. */
  5. public SimTok decode(final String token) {
  6. final int ndx = token.indexOf('.');
  7. final String p1 = token.substring(0, ndx);
  8. final int ndx2 = token.indexOf('.', ndx + 1);
  9. final String p2 = token.substring(ndx + 1, ndx2);
  10. final String p3 = token.substring(ndx2 + 1);
  11. if (!BCrypt.checkpw(p1 + "." + p2 + "." + SECRET, p3)) {
  12. return null;
  13. }
  14. final String p2Decoded = Base64.decodeToString(p2);
  15. return JsonParser.create().parse(p2Decoded, SimTok.class);
  16. }
  17. }

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

  1. @Test
  2. void testMergeInDepth1() {
  3. {
  4. JsonObject obj1 = JsonParser.create().parseAsJsonObject("{ \"foo\": \"bar\", \"flurb\": { \"eek\": \"foo\", \"bar\": \"flurb\"}}");
  5. JsonObject obj2 = JsonParser.create().parseAsJsonObject("{ \"flurb\": { \"bar\": \"flurb1\" }}");
  6. obj1.mergeIn(obj2, 1);
  7. assertEquals(2, obj1.size());
  8. assertEquals(1, obj1.getJsonObject("flurb").size());
  9. assertEquals("flurb1", obj1.getJsonObject("flurb").getString("bar"));
  10. }
  11. {
  12. JsonObject obj1 = JsonParser.createLazyOne().parseAsJsonObject("{ \"foo\": \"bar\", \"flurb\": { \"eek\": \"foo\", \"bar\": \"flurb\"}}");
  13. JsonObject obj2 = JsonParser.createLazyOne().parseAsJsonObject("{ \"flurb\": { \"bar\": \"flurb1\" }}");
  14. obj1.mergeIn(obj2, 1);
  15. assertEquals(2, obj1.size());
  16. assertEquals(1, obj1.getJsonObject("flurb").size());
  17. assertEquals("flurb1", obj1.getJsonObject("flurb").getString("bar"));
  18. }
  19. }

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

  1. public static void forEachParser(final Consumer<JsonParser> jsonParserConsumer) {
  2. for (int i = 0; i < 2; i++) {
  3. final JsonParser jsonParser;
  4. switch (i) {
  5. case 0: jsonParser = JsonParser.create(); break;
  6. case 1: jsonParser = JsonParser.create().lazy(true); break;
  7. default:
  8. throw new IllegalArgumentException("Not good.");
  9. }
  10. jsonParserConsumer.accept(jsonParser);
  11. }
  12. }
  13. }

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

  1. @Test
  2. void testMergeInDepth2() {
  3. {
  4. JsonObject obj1 = new JsonObject(JsonParser.create().parse("{ \"foo\": \"bar\", \"flurb\": { \"eek\": \"foo\", \"bar\": \"flurb\"}}"));
  5. JsonObject obj2 = new JsonObject(JsonParser.create().parse("{ \"flurb\": { \"bar\": \"flurb1\" }}"));
  6. obj1.mergeIn(obj2, 2);
  7. assertEquals(2, obj1.size());
  8. assertEquals(2, obj1.getJsonObject("flurb").size());
  9. assertEquals("foo", obj1.getJsonObject("flurb").getString("eek"));
  10. assertEquals("flurb1", obj1.getJsonObject("flurb").getString("bar"));
  11. }
  12. {
  13. JsonObject obj1 = new JsonObject(JsonParser.createLazyOne().parse("{ \"foo\": \"bar\", \"flurb\": { \"eek\": \"foo\", \"bar\": \"flurb\"}}"));
  14. JsonObject obj2 = new JsonObject(JsonParser.createLazyOne().parse("{ \"flurb\": { \"bar\": \"flurb1\" }}"));
  15. obj1.mergeIn(obj2, 2);
  16. assertEquals(2, obj1.size());
  17. assertEquals(2, obj1.getJsonObject("flurb").size());
  18. assertEquals("foo", obj1.getJsonObject("flurb").getString("eek"));
  19. assertEquals("flurb1", obj1.getJsonObject("flurb").getString("bar"));
  20. }
  21. }

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

  1. @Test
  2. void testUuidSerialization() {
  3. UUID uuid = UUID.randomUUID();
  4. String json = JsonSerializer
  5. .create()
  6. .serialize(uuid);
  7. UUID uuid2 = JsonParser
  8. .create()
  9. .parse(json, UUID.class);
  10. assertEquals(uuid, uuid2);
  11. }
  12. }

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

  1. @Test
  2. void testCustomMap() {
  3. JsonParsers.forEachParser(jsonParser -> {
  4. String json = "{\"userId\" : 123, \"name\": 456}";
  5. Map<String, Integer> map = jsonParser.parse(json);
  6. assertEquals(2, map.size());
  7. assertEquals(Integer.valueOf(123), map.get("userId"));
  8. assertEquals(Integer.valueOf(456), map.get("name"));
  9. Map<String, Long> map2 = JsonParser
  10. .create()
  11. .map(JsonParser.VALUES, Long.class)
  12. .parse(json);
  13. assertEquals(2, map2.size());
  14. assertEquals(Long.valueOf(123), map2.get("userId"));
  15. assertEquals(Long.valueOf(456), map2.get("name"));
  16. });
  17. JsonParsers.forEachParser(jsonParser -> {
  18. String json = "{\"123\" : \"hey\", \"456\": \"man\"}";
  19. Map<Long, String> map3 = jsonParser
  20. .map(JsonParser.KEYS, Long.class)
  21. .parse(json);
  22. assertEquals(2, map3.size());
  23. assertEquals("hey", map3.get(Long.valueOf(123)));
  24. assertEquals("man", map3.get(Long.valueOf(456)));
  25. });
  26. }

代码示例来源:origin: miyakowork/NoteBlog

  1. public static IpInfo getIpInfo(String ip) {
  2. String url = "http://ip.taobao.com/service/getIpInfo.php?ip=" + ip;
  3. String resp = HttpUtil.get(url);
  4. return JsonParser.create().parse(resp, IpInfo.class);
  5. }

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

  1. /**
  2. * Decodes the String to the {@link SimTok}.
  3. * Returns {@code null} if decoded token is NOT valid.
  4. */
  5. public SimTok decode(final String token) {
  6. final int ndx = token.indexOf('.');
  7. final String p1 = token.substring(0, ndx);
  8. final int ndx2 = token.indexOf('.', ndx + 1);
  9. final String p2 = token.substring(ndx + 1, ndx2);
  10. final String p3 = token.substring(ndx2 + 1);
  11. if (!BCrypt.checkpw(p1 + "." + p2 + "." + SECRET, p3)) {
  12. return null;
  13. }
  14. final String p2Decoded = Base64.decodeToString(p2);
  15. return JsonParser.create().parse(p2Decoded, SimTok.class);
  16. }
  17. }

相关文章