当前位置: 首页>>代码示例>>Java>>正文


Java JsonFactory.fromJson方法代码示例

本文整理汇总了Java中org.boon.json.JsonFactory.fromJson方法的典型用法代码示例。如果您正苦于以下问题:Java JsonFactory.fromJson方法的具体用法?Java JsonFactory.fromJson怎么用?Java JsonFactory.fromJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.boon.json.JsonFactory的用法示例。


在下文中一共展示了JsonFactory.fromJson方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: outgoing

import org.boon.json.JsonFactory; //导入方法依赖的package包/类
@Test
public void outgoing() throws Exception {
	Map<String, String> map = new HashMap<>();
	map.put("token", TOKEN);
	map.put("trigger_word", "@startuml");
	String content = "hogehoge";
	map.put("text", "@startuml\n" + content + "\[email protected]");

	Request request = new MockUp<Request>() {
		@Mock
		Optional<String> form(String key) {
			return Optional.ofNullable(map.get(key));
		}
	}.getMockInstance();
	Response response = new MockUp<Response>() {
	}.getMockInstance();
	Object obj = this.target.outgoing(request, response);
	assertNotNull(obj);
	System.out.println(obj);
	Msg msg = JsonFactory.fromJson(obj.toString(), Msg.class);
	assertNotNull(msg.text);
	assertTrue(msg.text.startsWith(HOST));

	Transcoder t = Uml.transcoder();
	String enc = t.encode(content);
	assertTrue(msg.text.endsWith(enc));
}
 
开发者ID:taichi,项目名称:umlbot,代码行数:28,代码来源:UmlTest.java

示例2: schemaLessTest

import org.boon.json.JsonFactory; //导入方法依赖的package包/类
@Test
public void schemaLessTest() throws Exception
{

    String name1 = "{\"name\":\"Travel Route1\", \"cities\": [ \"C1\", \"C2\", \"C3\" ],  " +
            "\"type\": \"route\" }";
    String name2 = "{\"name\":\"First Town\", \"type\": \"city\"}";
    String name3 = "{\"name\":\"Second Stop\", \"type\": \"city\"}";
    String name4 = "{\"name\":\"Destination\", \"type\": \"city\"}";

    try (PreparedStatement preparedStatement = con.prepareStatement("insert into default(key,value) values (?,?)"))
    {
        Map <String, String> jsonObject = (Map <String, String>)JsonFactory.fromJson(new StringReader(name1));
        preparedStatement.setString(1,"name");
        preparedStatement.setString(2, jsonObject.get("name"));

        assertEquals(1, preparedStatement.executeUpdate());

        jsonObject = (Map <String, String>)JsonFactory.fromJson(new StringReader(name2));
        preparedStatement.setString(1,"name1");
        preparedStatement.setString(2, jsonObject.get("name"));

        assertEquals(1, preparedStatement.executeUpdate());

        jsonObject = (Map <String, String>)JsonFactory.fromJson(new StringReader(name3));
        preparedStatement.setString(1,"name2");
        preparedStatement.setString(2, jsonObject.get("name"));

        assertEquals(1, preparedStatement.executeUpdate());

        jsonObject = (Map <String, String>)JsonFactory.fromJson(new StringReader(name4));
        preparedStatement.setString(1,"name3");
        preparedStatement.setString(2, jsonObject.get("name"));

        assertEquals(1, preparedStatement.executeUpdate());
    }
    /*
    try(Statement statement = con.createStatement())
    {
        ResultSet rs = statement.executeQuery("SELECT r.name as route_name, c as route_cities " +
                                                "FROM default r NEST travel c ON KEYS r.cities" +
                                                " WHERE r.name = \"Travel Route1\"");
        assertTrue(rs.next());
    }
    */

}
 
开发者ID:jdbc-json,项目名称:jdbc-cb,代码行数:48,代码来源:PreparedStatementTest.java

示例3: createCommand

import org.boon.json.JsonFactory; //导入方法依赖的package包/类
/** Return a Command object bearing a payload relevant to the given route,
 * or die trying and throw an exception. Never return null.
 *
 * Example command-line test query:
 * curl --data "state={\"r\":1.0,\"g\":0.5,\"b\":0.25}" localhost:8080/mixer0/layer0
 */
public Command createCommand(Request request)
        throws UnsupportedEncodingException,
        RoutingException,
        CommandParserException,
        SoftenedException, // generic wrapper for a boon JSON parser exception
        ClassCastException // sometimes a Boon JSON parser exception in disguise
{
    Query query = request.getQuery();
    Path path = request.getPath();
    String route = path.toString();
    Class stateClass = this.commandMap.get(route);

    if (stateClass == null) {
        throw new RoutingException("No route for path: " + route);

    } else {
        String rawState = query.get("state");
        if (rawState == null) {
            throw new CommandParserException("The 'state' request param is required for " + route);

        } else {
            String json = URLDecoder.decode(rawState, "UTF-8");
            if (json == null) {
                throw new CommandParserException("Failed to URL-decode a raw JSON string for " + route);

            } else {
                // This works fine, but the JsonFactory for some reason wants a
                // Class<T>, not a plain class. Causes an unchecked conversion warning.
                Object state = JsonFactory.fromJson(json, stateClass);
                if (state == null) {
                    throw new CommandParserException(
                            "Failed to deserialize a JSON command of length "
                                    + json.length() + " for " + route);

                } else if (state.getClass() == stateClass) {
                    return new Command(route, state);

                } else {
                    throw new CommandParserException(
                            "Failed to convert a command of length "
                                    + json.length() + " for " + route + " into a "
                                    + stateClass.getSimpleName() + ".");
                }
            }
        }
    }
}
 
开发者ID:coil-lighting,项目名称:udder,代码行数:54,代码来源:HttpServiceContainer.java


注:本文中的org.boon.json.JsonFactory.fromJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。