本文整理汇总了Java中com.fasterxml.jackson.jr.ob.JSON类的典型用法代码示例。如果您正苦于以下问题:Java JSON类的具体用法?Java JSON怎么用?Java JSON使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSON类属于com.fasterxml.jackson.jr.ob包,在下文中一共展示了JSON类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReadWrite
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Test
public void testReadWrite() throws Exception {
// writer a simple json file
Map<String, Object> json = new HashMap<>();
json.put("a", "c");
File tmp = folder.newFolder("drill");
File out = new File(tmp, "test.json");
JSON j = JSON.std;
j.write(json, out);
try (Connection conn = drill.getConnection()) {
conn.createStatement().execute("ALTER SESSION SET `store.format`='json'");
String select = String.format("SELECT * FROM dfs.`%s`", out.getPath());
ResultSet results = conn.createStatement().executeQuery(select);
assertTrue(results.next());
assertEquals(json.get("a"), results.getString("a"));
assertEquals(1, results.getMetaData().getColumnCount());
}
}
示例2: convert
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
public void convert(Map<String, String> eventProperties, StringBuilder appendTo) {
Map<String, String> properties = mergeContextMaps(eventProperties);
if (properties != null && !properties.isEmpty()) {
try {
/*
* -- let's compose an JSON object, then chop off the outermost
* curly braces
*/
ObjectComposer<JSONComposer<String>> oc = JSON.std.composeString().startObject();
for (Entry<String, String> p: properties.entrySet()) {
if (!exclusions.contains(p.getKey())) {
oc.put(p.getKey(), p.getValue());
}
}
String result = oc.end().finish().trim();
appendTo.append(result.substring(1, result.length() - 1));
} catch (Exception ex) {
/* -- avoids substitute logger warnings on startup -- */
LoggerFactory.getLogger(DefaultPropertiesConverter.class).error("Conversion failed ", ex);
}
}
}
示例3: convert
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
public void convert(String message, StringBuilder appendTo) {
if (message != null) {
String result;
if (flatten) {
result = flattenMsg(message);
} else {
result = message;
}
if (escape) {
try {
appendTo.append(JSON.std.asString(result));
} catch (Exception ex) {
/* -- avoids substitute logger warnings on startup -- */
LoggerFactory.getLogger(DefaultMessageConverter.class).error("Conversion failed ", ex);
appendTo.append(result);
}
} else {
appendTo.append(result);
}
}
}
示例4: toString
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Override
public String toString() {
/*
* -- make sure we have set start and end time
*/
finish();
try {
JSONComposer<String> jc = JSON.std.composeString();
ObjectComposer<JSONComposer<String>> oc = jc.startObject();
for (Entry<String, Value> value: fields.entrySet()) {
oc.putObject(value.getKey(), value.getValue().getValue());
}
return oc.end().finish();
} catch (Exception ex) {
return "{}";
}
}
示例5: testDevice
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Test
public void testDevice() throws Exception {
Device device = this.deserialize(
Device.class,
JSON.std
.composeString()
.startObject()
.put("confidence", 99)
.put("id", "C8D3BE1A-BE26-11E5-8C50-1B575C37265F")
.put("last_seen", "2016-06-08T14:16:38Z")
.end()
.finish()
);
assertEquals(99.0, device.getConfidence(), 1e-15);
assertEquals(UUID.fromString("C8D3BE1A-BE26-11E5-8C50-1B575C37265F"), device.getId());
assertEquals("2016-06-08T14:16:38Z", device.getLastSeen());
}
示例6: testEmail
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Test
public void testEmail() throws Exception {
Email email = this.deserialize(
Email.class,
JSON.std
.composeString()
.startObject()
.put("is_free", false)
.put("is_high_risk", true)
.put("first_seen", "2017-01-02")
.end()
.finish()
);
assertFalse(email.isFree());
assertTrue(email.isHighRisk());
assertEquals(email.getFirstSeen(), "2017-01-02");
}
示例7: testEmailWithoutFirstSeen
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Test
public void testEmailWithoutFirstSeen() throws Exception {
Email email = this.deserialize(
Email.class,
JSON.std
.composeString()
.startObject()
.put("is_free", false)
.put("is_high_risk", true)
.end()
.finish()
);
assertFalse(email.isFree());
assertTrue(email.isHighRisk());
assertNull(email.getFirstSeen());
}
示例8: testIssuer
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Test
public void testIssuer() throws Exception {
String phone = "132-342-2131";
Issuer issuer = this.deserialize(
Issuer.class,
JSON.std
.composeString()
.startObject()
.put("name", "Bank")
.put("matches_provided_name", true)
.put("phone_number", phone)
.put("matches_provided_phone_number", true)
.end()
.finish()
);
assertEquals("bank name", "Bank", issuer.getName());
assertTrue("provided name matches", issuer.matchesProvidedName());
assertEquals("phone", phone, issuer.getPhoneNumber());
assertTrue("provided phone matches", issuer.matchesProvidedPhoneNumber());
}
示例9: testCreditCard
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Test
public void testCreditCard() throws Exception {
CreditCard cc = this.deserialize(
CreditCard.class,
JSON.std
.composeString()
.startObject()
.startObjectField("issuer")
.put("name", "Bank")
.end()
.put("brand", "Visa")
.put("country", "US")
.put("is_issued_in_billing_address_country", true)
.put("is_prepaid", true)
.put("type", "credit")
.end()
.finish()
);
assertEquals("Bank", cc.getIssuer().getName());
assertEquals("US", cc.getCountry());
assertEquals("Visa", cc.getBrand());
assertEquals("credit", cc.getType());
assertTrue(cc.isPrepaid());
assertTrue(cc.isIssuedInBillingAddressCountry());
}
示例10: testShippingAddress
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Test
public void testShippingAddress() throws Exception {
ShippingAddress address = this.deserialize(
ShippingAddress.class,
JSON.std
.composeString()
.startObject()
.put("is_in_ip_country", true)
.put("latitude", 43.1)
.put("longitude", 32.1)
.put("distance_to_ip_location", 100)
.put("is_postal_in_city", true)
.put("is_high_risk", false)
.put("distance_to_billing_address", 200)
.end()
.finish()
);
this.testAddress(address);
assertFalse("is high risk", address.isHighRisk());
assertEquals("distance to billing address", Integer.valueOf(200), address.getDistanceToBillingAddress());
}
示例11: testDisposition
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Test
public void testDisposition() throws Exception {
Disposition disposition = this.deserialize(
Disposition.class,
JSON.std
.composeString()
.startObject()
.put("action", "accept")
.put("reason", "default")
.end()
.finish()
);
assertEquals("accept", disposition.getAction());
assertEquals("default", disposition.getReason());
}
示例12: testWarningn
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Test
public void testWarningn() throws Exception {
String code = "INVALID_INPUT";
String msg = "Input invalid";
String pointer = "/first/second";
Warning warning = this.deserialize(
Warning.class,
JSON.std
.composeString()
.startObject()
.put("code", code)
.put("warning", msg)
.put("input_pointer", pointer)
.end()
.finish()
);
assertEquals("code", code, warning.getCode());
assertEquals("warning message", msg, warning.getWarning());
assertEquals("input_pointer", pointer, warning.getInputPointer());
}
示例13: testBillingAddress
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Test
public void testBillingAddress() throws Exception {
BillingAddress address = this.deserialize(BillingAddress.class,
JSON.std
.composeString()
.startObject()
.put("is_in_ip_country", true)
.put("latitude", 43.1)
.put("longitude", 32.1)
.put("distance_to_ip_location", 100)
.put("is_postal_in_city", true)
.end()
.finish()
);
this.testAddress(address);
}
示例14: decode
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Override
public String decode(
final Object value,
final Class type
) throws KernelException {
ArgumentChecker.required(value, "value");
ArgumentChecker.required(type, "type");
if (type.equals(String.class) && value instanceof String) {
return value.toString();
}
try {
return JSON.std.asString(value);
} catch (Exception ex) {
throw new KernelException(ex);
}
}
示例15: encode
import com.fasterxml.jackson.jr.ob.JSON; //导入依赖的package包/类
@Override
public Object encode(
final String value,
final Class type
) throws KernelException {
ArgumentChecker.required(value, "value");
ArgumentChecker.required(type, "type");
if (type.equals(String.class)) {
return value;
}
try {
if (type.equals(Map.class)) {
return JSON.std.mapFrom(value);
} else if (type.equals(List.class)) {
return JSON.std.listFrom(value);
} else {
return JSON.std.beanFrom(type, value);
}
} catch (Exception ex) {
throw new KernelException(ex);
}
}