本文整理汇总了Java中org.boon.json.JsonFactory类的典型用法代码示例。如果您正苦于以下问题:Java JsonFactory类的具体用法?Java JsonFactory怎么用?Java JsonFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonFactory类属于org.boon.json包,在下文中一共展示了JsonFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: givenDateTypes_shouldSerialize
import org.boon.json.JsonFactory; //导入依赖的package包/类
@Test
public void givenDateTypes_shouldSerialize() throws ParseException {
/*
{
"date": 1514160000000,
"dayOfWeek": "MONDAY",
"zoneId": {
"class": "java.time.ZoneRegion",
"id": "Europe/London"
}
}
Boon does not seem to support Java 8 dates.
*/
String expectedJson = "{\"date\":1514160000000,\"dayOfWeek\":\"MONDAY\",\"zoneId\":{\"class\":\"java.time.ZoneRegion\",\"id\":\"Europe/London\"}}";
String actualJson = JsonFactory.create().toJson(new AllDateTypes());
assertThat(actualJson).isEqualTo(expectedJson);
}
示例2: givenDefaultValues_shouldSerialise
import org.boon.json.JsonFactory; //导入依赖的package包/类
@Test
public void givenDefaultValues_shouldSerialise() {
/*
{
"byteWrapper": 0,
"shortWrapper": 0,
"charWrapper": "",
"intWrapper": 0,
"longWrapper": 0,
"floatWrapper": 0,
"doubleWrapper": 0,
"string": "Hello World"
}
*/
String expectedJson ="{\"byteWrapper\":0,\"shortWrapper\":0,\"charWrapper\":\"\",\"intWrapper\":0,\"longWrapper\":0,\"floatWrapper\":0.0,\"doubleWrapper\":0.0,\"string\":\"Hello World\"}";
AllBasicTypes allBasicTypes = new AllBasicTypes();
String actualJson = JsonFactory.create().toJson(allBasicTypes);
assertThat(actualJson).isEqualTo(expectedJson);
}
示例3: 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);
}
示例4: 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);
}
}
示例5: 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);
}
示例6: parsePatchSheet
import org.boon.json.JsonFactory; //导入依赖的package包/类
/** Parse the JSON patch sheet as an array of Devices wrapped in a
* PatchSheet.
*/
public static PatchSheet parsePatchSheet(String configPath)
throws DeviceAddressException, IOException {
// When you need to debug JSON parsing, these two calls help:
// byte[] encoded = Files.readAllBytes(Paths.get(configPath));
// String json = new String(encoded, StandardCharsets.UTF_8);
List<PatchElement> patchElements = JsonFactory.fromJsonArray(
FileUtil.fileToString(configPath), PatchElement.class);
List<Device> devices = new ArrayList<Device>(patchElements.size());
for(PatchElement pe: patchElements) {
devices.add(pe.toDevice());
}
return new PatchSheet(devices);
}
示例7: givenJavaTypes_shouldSerialise
import org.boon.json.JsonFactory; //导入依赖的package包/类
@Test
public void givenJavaTypes_shouldSerialise() throws MalformedURLException, URISyntaxException {
/*
{
"bigInteger": 10,
"bigDecimal": 10,
"url": "http://www.readlearncode.com",
"uri": "http://www.readlearncode.com"
}
*/
String expectedJson = "{\"bigInteger\":10,\"bigDecimal\":10,\"url\":\"http://www.readlearncode.com\",\"uri\":\"http://www.readlearncode.com\"}";
String actualJson = JsonFactory.create().toJson(new JavaTypes());
assertThat(actualJson).isEqualTo(expectedJson);
}
示例8: givenCalendarType_shouldSerialise
import org.boon.json.JsonFactory; //导入依赖的package包/类
@Test @Ignore("Boon uses toString to construct property value")
public void givenCalendarType_shouldSerialise() {
/*
*/
String expectedJson = "{\"calendar1\":\""+new CalendarType().getCalendar1().toString()+"\"}";
String actualJson = JsonFactory.create().toJson(new CalendarType());
assertThat(actualJson).isEqualTo(expectedJson);
}
示例9: send
import org.boon.json.JsonFactory; //导入依赖的package包/类
public void send(Object obj) {
if (httpServerExchange.getRequestMethod()
.equals(HEAD)) {
httpServerExchange.endExchange();
return;
}
httpServerExchange.getResponseHeaders()
.put(Headers.CONTENT_TYPE, JSON_CONTENT_TYPE);
ObjectMapper objectMapper = LOCAL_MAPPER.get();
if (objectMapper == null) {
LOGGER.info("Creating new parser.........");
objectMapper = JsonFactory.createUseJSONDates();
LOCAL_MAPPER.set(objectMapper);
}
String jsonStr = objectMapper
.toJson(obj);
ByteBuffer byteBuffer = ByteBuffer.wrap(jsonStr.getBytes(StandardCharsets.UTF_8));
StreamSinkChannel responseChannel = httpServerExchange.getResponseChannel();
int written;
try {
do {
written = responseChannel.write(byteBuffer);
} while (byteBuffer.hasRemaining() && written > 0);
} catch (IOException e) {
LOGGER.error("Can not write response: " + e.getMessage(), e);
}
}
示例10: CBArray
import org.boon.json.JsonFactory; //导入依赖的package包/类
CBArray(List arrayList)
{
if (arrayList == null )
{
array=null;
jsonArray=null;
}
else
{
array = arrayList.toArray();
jsonArray = JsonFactory.toJson(array);
}
}
示例11: getStringChecked
import org.boon.json.JsonFactory; //导入依赖的package包/类
private String getStringChecked(String columnLabel) throws SQLException
{
Map <String,Object>jsonObject = response.getResults().get(index);
if (checkColumnLabelMissing(jsonObject, columnLabel))
{
return null;
}
Object object = jsonObject.get(columnLabel);
if (wasNull = (object == null))
{
return null;
}
if (object instanceof Map)
{
return JsonFactory.toJson(object);
}
else
{
if (!(object instanceof String))
{
return object.toString();
}
else
return (String)object;
}
}
示例12: toJson
import org.boon.json.JsonFactory; //导入依赖的package包/类
private synchronized void toJson()
{
if (sqlJson == null )
{
sqlJson = JsonFactory.toJson(jsonObject);
}
}
示例13: 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());
}
}
示例14: 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);
}
示例15: 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));
}