本文整理汇总了Java中org.boon.json.JsonFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Java JsonFactory.create方法的具体用法?Java JsonFactory.create怎么用?Java JsonFactory.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.boon.json.JsonFactory
的用法示例。
在下文中一共展示了JsonFactory.create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JsonBoon
import org.boon.json.JsonFactory; //导入方法依赖的package包/类
public JsonBoon() {
JsonParserFactory jsonParserFactory = new JsonParserFactory();
jsonParserFactory.lax();
// Include nulls and empty fields
JsonSerializerFactory serializerFactory = new JsonSerializerFactory();
serializerFactory.setIncludeNulls(true);
serializerFactory.setIncludeEmpty(true);
// Install MongoDB / BSON serializers
tryToAddSerializers("io.datatree.dom.adapters.JsonBoonBsonSerializers", serializerFactory);
// Format dates
serializerFactory.setJsonFormatForDates(Config.USE_TIMESTAMPS);
mapper = JsonFactory.create(jsonParserFactory, serializerFactory);
}
示例2: testBadInstance
import org.boon.json.JsonFactory; //导入方法依赖的package包/类
@Test
public void testBadInstance() throws Exception
{
Cluster cluster = ((ProtocolImpl)((CBConnection) con).protocol).getCluster();
String endpoint = "{\"cluster\":\"default\",\"name\":\"10.168.209.119\",\"queryEndpoint\":\"http://10.168.209.119:8093/query/service\"," +
"\"adminEndpoint\":\"http://10.168.209.119:8093/admin\",\"options\":null}";
ObjectMapper mapper = JsonFactory.create();
Map <String,Object> instanceEndpoint = (Map)mapper.fromJson(endpoint);
cluster.addEndPoint(instanceEndpoint);
assertNotNull(con);
Statement statement = con.createStatement();
assertNotNull(statement);
// there are only 4 endpoints we added 1 which is 5
for (int i = 0; i++< 6;)
{
int inserted = statement.executeUpdate("INSERT INTO default (KEY, VALUE) VALUES ( 'K" + i +"'," + i +")");
assertEquals(1, inserted);
}
}
示例3: toJsonString
import org.boon.json.JsonFactory; //导入方法依赖的package包/类
public static <T> String toJsonString(T document) {
JsonSerializerFactory serializer = new JsonSerializerFactory().addFilter(new FieldFilter() {
@Override
public boolean include(Object o, FieldAccess fieldAccess) {
if ( fieldAccess.hasAnnotation(DocumentRef.class.getName())) {
return false;
}
return true;
}
});
ObjectMapper mapper = JsonFactory.create(null, serializer);
return mapper.toJson(document);
}
示例4: setSqlJson
import org.boon.json.JsonFactory; //导入方法依赖的package包/类
@Test
public void setSqlJson() throws Exception
{
String json = "{\n" +
" \"emailAddress\": \"[email protected]\",\n" +
" \"type\": \"customer\",\n" +
" \"dateLastActive\": \"2014-05-06T15:52:14Z\",\n" +
" \"firstName\": \"Darrin\",\n" +
" \"phoneNumber\": \"497-854-2229 x000\",\n" +
" \"postalCode\": \"45603-9112\",\n" +
" \"lastName\": \"Ortiz\",\n" +
" \"ccInfo\": {\n" +
" \"cardNumber\": \"1234-2121-1221-1211\",\n" +
" \"cardType\": \"discover\",\n" +
" \"cardExpiry\": \"2012-11-12\"\n" +
" },\n" +
" \"dateAdded\": \"2013-06-10T15:52:14Z\",\n" +
" \"state\": \"IN\",\n" +
" \"customerId\": \"customer10\"\n" +
"}";
ObjectMapper mapper = JsonFactory.create();
Map <String,Object> jsonObject = mapper.readValue(json, Map.class);
String query = "insert into default (key,value) values (?,?)";
SQLJSON sqljson = ((CBConnection)con).createSQLJSON();
sqljson.setMap( jsonObject );
try (PreparedStatement pstmt = con.prepareStatement(query))
{
pstmt.setString(1,"customer1");
((CBPreparedStatement)pstmt).setSQLJSON(2,sqljson);
assertEquals(1,pstmt.executeUpdate());
}
}
示例5: save
import org.boon.json.JsonFactory; //导入方法依赖的package包/类
@Test
public void save() throws Exception {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
EventRepositoryFS repo = new EventRepositoryFS("test.json");
Beer b1 = new Beer("Åbro Orginal", "Damm", "Lager", 213124, 23.2, "Åbro", "Sverige", "", 5.2, "flaska", "öl", true, 50, formatter.parse("2005-10-01"), "Åbro", "", 213124);
Beer b2 = new Beer("Norrlands guld", "Hopps", "Lager", 14127, 19.5, "Spendrups", "Sverige", "", 5, "flaska", "öl", true, 330, formatter.parse("2005-10-01"), "Spendrups", "", 14127);
Beer b3 = new Beer("Åbro Orginal", "Damm", "Lager", 213124, 23.2, "Åbro", "England", "", 5.2, "flaska", "öl", true, 50, formatter.parse("2005-10-01"), "Åbro", "", 213124);
Beer b4 = new Beer("Falcon", "Njet", "Lager", 95483, 20, "Falcon", "Sverige", "", 4.8, "flaska", "öl", true, 335, formatter.parse("1999-10-01"), "Spendrups", "", 95483);
Event e1 = new Event(213124, Event.Action.Update, b1, b3);
Event e2 = new Event(14127, Event.Action.Create, new Beer(), b2);
Event e3 = new Event(95483, Event.Action.Delete, b4, new Beer());
List<Event> eventList = new ArrayList<>();
eventList.add(e1);
eventList.add(e2);
eventList.add(e3);
repo.save(eventList);
ObjectMapper mapper = JsonFactory.create();
List<Event> events = new ArrayList<>();
try {
events = mapper.readValue(new FileInputStream("test.json"), List.class, Event.class);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//puts("events", events);
System.out.println(eventList.get(0).toString());
System.out.println(events.get(0).toString());
assertEquals(eventList, events);
}
示例6: handleClusterResponse
import org.boon.json.JsonFactory; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public Cluster handleClusterResponse(CloseableHttpResponse response) throws IOException
{
int status = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
String string = EntityUtils.toString(entity);
logger.trace ("Cluster response {}", string);
ObjectMapper mapper = JsonFactory.create();
// has to be an object here since we can get a 404 back which is a string
Object jsonArray = mapper.fromJson(string);
String message="";
switch (status)
{
case 200:
//noinspection unchecked
rewriteURLs((List<Map>)jsonArray);
return new Cluster((List)jsonArray, ssl);
case 400:
message = "Bad Request";
break;
case 401:
message = "Unauthorized Request credentials are missing or invalid";
break;
case 403:
message = "Forbidden Request: read only violation or client unauthorized to modify";
break;
case 404:
message = "Not found: Check the URL";
break;
case 405:
message = "Method not allowed: The REST method type in request is supported";
break;
case 409:
message = "Conflict: attempt to create a keyspace or index that already exists";
break;
case 410:
message = "Gone: The server is doing a graceful shutdown";
break;
case 500:
message = "Internal server error: unforeseen problem processing the request";
break;
case 503:
message = "Service Unavailable: there is an issue preventing the request from being serv serviced";
break;
}
throw new ClientProtocolException(message +": " + status);
}
示例7: createInstanceFromJsonString
import org.boon.json.JsonFactory; //导入方法依赖的package包/类
public static <T> T createInstanceFromJsonString(final Class<T> document,final String jsonData) {
ObjectMapper mapper = JsonFactory.create();
return mapper.readValue(jsonData,document);
}
示例8: BoonDataFormat
import org.boon.json.JsonFactory; //导入方法依赖的package包/类
/**
* Use the default Boon {@link ObjectMapper} and with a custom unmarshal
* type
*
* @param unmarshalType the custom unmarshal type
*/
public BoonDataFormat(Class<?> unmarshalType) {
this(unmarshalType, JsonFactory.create());
}