Java Code Examples for org.boon.json.JsonFactory#fromJson()

The following examples show how to use org.boon.json.JsonFactory#fromJson() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UmlTest.java    From umlbot with GNU General Public License v3.0 5 votes vote down vote up
@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 + "\n@enduml");

	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));
}
 
Example 2
Source File: PreparedStatementTest.java    From jdbc-cb with Apache License 2.0 4 votes vote down vote up
@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());
    }
    */

}
 
Example 3
Source File: Bug312.java    From boon with Apache License 2.0 4 votes vote down vote up
@Test
public void test() {

    MyClass myClass = new MyClass();
    final String json = JsonFactory.toJson(myClass);

    final MyClass myClass1 = JsonFactory.fromJson(json, MyClass.class);

    assertEquals("foo", myClass1.string);

    assertEquals(1, myClass1.integer);


    assertNull(myClass1.map);


}
 
Example 4
Source File: Bug312.java    From boon with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithMap() {

    MyClass myClass = new MyClass();
    myClass.map = new HashMap<>();
    myClass.map.put("foo", "bar");
    final String json = JsonFactory.toJson(myClass);

    final MyClass myClass1 = JsonFactory.fromJson(json, MyClass.class);

    assertEquals("foo", myClass1.string);

    assertEquals(1, myClass1.integer);


    assertEquals("bar", myClass1.map.get("foo"));


}
 
Example 5
Source File: BugReport165AndIssue169.java    From boon with Apache License 2.0 4 votes vote down vote up
@Test
public void test4() {
    Sample sample1 = new Sample();
    String json = JsonFactory.toJson(sample1);
    puts(json);
    puts (sample1);

    ok = json.contains("\"effectiveDate\"") || die();

    Sample sample2 = JsonFactory.fromJson(json, Sample.class);

    puts ("sample2", sample2);

    puts ("sample2", JsonFactory.toJson(sample2));

    ok = sample1.equals(sample2);

}
 
Example 6
Source File: Bug311.java    From boon with Apache License 2.0 3 votes vote down vote up
@Test
public  void test () {



    final String json = JsonFactory.toJson(new SimpleObject());

    final SimpleObject simpleObject = JsonFactory.fromJson(json, SimpleObject.class);

    assertEquals(Float.NEGATIVE_INFINITY, simpleObject.f1, 0.1);

    assertEquals(Float.NaN, simpleObject.f2, 0.1);

}
 
Example 7
Source File: Boon.java    From boon with Apache License 2.0 2 votes vote down vote up
/**
 * Helper method to quickly convert JSON into a Java object.
 * Facade into the JSON system.
 *
 * @param value JSON content
 * @return Java object
 */
public static Object fromJson(String value) {
    return JsonFactory.fromJson(value);
}
 
Example 8
Source File: Boon.java    From boon with Apache License 2.0 2 votes vote down vote up
/**
 * Helper method to quickly convert JSON into a Java object.
 * Facade into the JSON system.
 *
 * @param value JSON content
 * @param clazz type you want to convert the JSON to
 * @return Java object
 */
public static <T> T fromJson(String value, Class<T> clazz) {
    return JsonFactory.fromJson(value, clazz);
}