本文整理了Java中jodd.json.JsonParser.create()
方法的一些代码示例,展示了JsonParser.create()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonParser.create()
方法的具体详情如下:
包路径:jodd.json.JsonParser
类名称:JsonParser
方法名:create
[英]Static ctor.
[中]静态选择器。
代码示例来源:origin: oblac/jodd
/**
* Parses request body into the target type.
*/
protected Object parseRequestBody(final String body, final Class targetType) {
return JsonParser.create().parse(body, targetType);
}
代码示例来源:origin: oblac/jodd
@Test
void testMergeInDepth0() {
{
JsonObject obj1 = JsonParser.create().parseAsJsonObject("{ \"foo\": { \"bar\": \"flurb\" }}");
JsonObject obj2 = JsonParser.create().parseAsJsonObject("{ \"foo\": { \"bar\": \"eek\" }}");
obj1.mergeIn(obj2, 0);
assertEquals(1, obj1.size());
assertEquals(1, obj1.getJsonObject("foo").size());
assertEquals("flurb", obj1.getJsonObject("foo").getString("bar"));
}
{
JsonObject obj1 = JsonParser.createLazyOne().parseAsJsonObject("{ \"foo\": { \"bar\": \"flurb\" }}");
JsonObject obj2 = JsonParser.createLazyOne().parseAsJsonObject("{ \"foo\": { \"bar\": \"eek\" }}");
obj1.mergeIn(obj2, 0);
assertEquals(1, obj1.size());
assertEquals(1, obj1.getJsonObject("foo").size());
assertEquals("flurb", obj1.getJsonObject("foo").getString("bar"));
}
}
代码示例来源:origin: oblac/jodd
/**
* Decodes the String to the {@link SimTok}.
* Returns {@code null} if decoded token is NOT valid.
*/
public SimTok decode(final String token) {
final int ndx = token.indexOf('.');
final String p1 = token.substring(0, ndx);
final int ndx2 = token.indexOf('.', ndx + 1);
final String p2 = token.substring(ndx + 1, ndx2);
final String p3 = token.substring(ndx2 + 1);
if (!BCrypt.checkpw(p1 + "." + p2 + "." + SECRET, p3)) {
return null;
}
final String p2Decoded = Base64.decodeToString(p2);
return JsonParser.create().parse(p2Decoded, SimTok.class);
}
}
代码示例来源:origin: oblac/jodd
@Test
void testMergeInDepth1() {
{
JsonObject obj1 = JsonParser.create().parseAsJsonObject("{ \"foo\": \"bar\", \"flurb\": { \"eek\": \"foo\", \"bar\": \"flurb\"}}");
JsonObject obj2 = JsonParser.create().parseAsJsonObject("{ \"flurb\": { \"bar\": \"flurb1\" }}");
obj1.mergeIn(obj2, 1);
assertEquals(2, obj1.size());
assertEquals(1, obj1.getJsonObject("flurb").size());
assertEquals("flurb1", obj1.getJsonObject("flurb").getString("bar"));
}
{
JsonObject obj1 = JsonParser.createLazyOne().parseAsJsonObject("{ \"foo\": \"bar\", \"flurb\": { \"eek\": \"foo\", \"bar\": \"flurb\"}}");
JsonObject obj2 = JsonParser.createLazyOne().parseAsJsonObject("{ \"flurb\": { \"bar\": \"flurb1\" }}");
obj1.mergeIn(obj2, 1);
assertEquals(2, obj1.size());
assertEquals(1, obj1.getJsonObject("flurb").size());
assertEquals("flurb1", obj1.getJsonObject("flurb").getString("bar"));
}
}
代码示例来源:origin: oblac/jodd
public static void forEachParser(final Consumer<JsonParser> jsonParserConsumer) {
for (int i = 0; i < 2; i++) {
final JsonParser jsonParser;
switch (i) {
case 0: jsonParser = JsonParser.create(); break;
case 1: jsonParser = JsonParser.create().lazy(true); break;
default:
throw new IllegalArgumentException("Not good.");
}
jsonParserConsumer.accept(jsonParser);
}
}
}
代码示例来源:origin: oblac/jodd
@Test
void testMergeInDepth2() {
{
JsonObject obj1 = new JsonObject(JsonParser.create().parse("{ \"foo\": \"bar\", \"flurb\": { \"eek\": \"foo\", \"bar\": \"flurb\"}}"));
JsonObject obj2 = new JsonObject(JsonParser.create().parse("{ \"flurb\": { \"bar\": \"flurb1\" }}"));
obj1.mergeIn(obj2, 2);
assertEquals(2, obj1.size());
assertEquals(2, obj1.getJsonObject("flurb").size());
assertEquals("foo", obj1.getJsonObject("flurb").getString("eek"));
assertEquals("flurb1", obj1.getJsonObject("flurb").getString("bar"));
}
{
JsonObject obj1 = new JsonObject(JsonParser.createLazyOne().parse("{ \"foo\": \"bar\", \"flurb\": { \"eek\": \"foo\", \"bar\": \"flurb\"}}"));
JsonObject obj2 = new JsonObject(JsonParser.createLazyOne().parse("{ \"flurb\": { \"bar\": \"flurb1\" }}"));
obj1.mergeIn(obj2, 2);
assertEquals(2, obj1.size());
assertEquals(2, obj1.getJsonObject("flurb").size());
assertEquals("foo", obj1.getJsonObject("flurb").getString("eek"));
assertEquals("flurb1", obj1.getJsonObject("flurb").getString("bar"));
}
}
代码示例来源:origin: oblac/jodd
@Test
void testUuidSerialization() {
UUID uuid = UUID.randomUUID();
String json = JsonSerializer
.create()
.serialize(uuid);
UUID uuid2 = JsonParser
.create()
.parse(json, UUID.class);
assertEquals(uuid, uuid2);
}
}
代码示例来源:origin: oblac/jodd
@Test
void testCustomMap() {
JsonParsers.forEachParser(jsonParser -> {
String json = "{\"userId\" : 123, \"name\": 456}";
Map<String, Integer> map = jsonParser.parse(json);
assertEquals(2, map.size());
assertEquals(Integer.valueOf(123), map.get("userId"));
assertEquals(Integer.valueOf(456), map.get("name"));
Map<String, Long> map2 = JsonParser
.create()
.map(JsonParser.VALUES, Long.class)
.parse(json);
assertEquals(2, map2.size());
assertEquals(Long.valueOf(123), map2.get("userId"));
assertEquals(Long.valueOf(456), map2.get("name"));
});
JsonParsers.forEachParser(jsonParser -> {
String json = "{\"123\" : \"hey\", \"456\": \"man\"}";
Map<Long, String> map3 = jsonParser
.map(JsonParser.KEYS, Long.class)
.parse(json);
assertEquals(2, map3.size());
assertEquals("hey", map3.get(Long.valueOf(123)));
assertEquals("man", map3.get(Long.valueOf(456)));
});
}
代码示例来源:origin: miyakowork/NoteBlog
public static IpInfo getIpInfo(String ip) {
String url = "http://ip.taobao.com/service/getIpInfo.php?ip=" + ip;
String resp = HttpUtil.get(url);
return JsonParser.create().parse(resp, IpInfo.class);
}
代码示例来源:origin: org.jodd/jodd-joy
/**
* Decodes the String to the {@link SimTok}.
* Returns {@code null} if decoded token is NOT valid.
*/
public SimTok decode(final String token) {
final int ndx = token.indexOf('.');
final String p1 = token.substring(0, ndx);
final int ndx2 = token.indexOf('.', ndx + 1);
final String p2 = token.substring(ndx + 1, ndx2);
final String p3 = token.substring(ndx2 + 1);
if (!BCrypt.checkpw(p1 + "." + p2 + "." + SECRET, p3)) {
return null;
}
final String p2Decoded = Base64.decodeToString(p2);
return JsonParser.create().parse(p2Decoded, SimTok.class);
}
}
内容来源于网络,如有侵权,请联系作者删除!