本文整理匯總了Java中com.fasterxml.jackson.core.JsonParser.close方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonParser.close方法的具體用法?Java JsonParser.close怎麽用?Java JsonParser.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.fasterxml.jackson.core.JsonParser
的用法示例。
在下文中一共展示了JsonParser.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testUtf8Issue462
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public void testUtf8Issue462() throws Exception
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
IOContext ioc = new IOContext(new BufferRecycler(), bytes, true);
JsonGenerator gen = new UTF8JsonGenerator(ObjectWriteContext.empty(), ioc, 0, bytes,
JsonFactory.DEFAULT_ROOT_VALUE_SEPARATOR, null, null);
String str = "Natuurlijk is alles gelukt en weer een tevreden klant\uD83D\uDE04";
int length = 4000 - 38;
for (int i = 1; i <= length; ++i) {
gen.writeNumber(1);
}
gen.writeString(str);
gen.flush();
gen.close();
// Also verify it's parsable?
JsonParser p = JSON_F.createParser(ObjectReadContext.empty(), bytes.toByteArray());
for (int i = 1; i <= length; ++i) {
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(1, p.getIntValue());
}
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals(str, p.getText());
assertNull(p.nextToken());
p.close();
}
示例2: parsePerson
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public static void parsePerson() {
try {
JsonFactory jsonfactory = new JsonFactory();
JsonParser parser = jsonfactory.createParser(new File("Person.json"));
while (parser.nextToken() != JsonToken.END_OBJECT) {
String token = parser.getCurrentName();
if ("firstname".equals(token)) {
parser.nextToken();
String fname = parser.getText();
out.println("firstname : " + fname);
}
if ("lastname".equals(token)) {
parser.nextToken();
String lname = parser.getText();
out.println("lastname : " + lname);
}
if ("phone".equals(token)) {
parser.nextToken();
long phone = parser.getLongValue();
out.println("phone : " + phone);
}
if ("address".equals(token)) {
out.println("address :");
parser.nextToken();
while (parser.nextToken() != JsonToken.END_ARRAY) {
out.println(parser.getText());
}
}
}
parser.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
示例3: jsonToHostDefinition
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
protected void jsonToHostDefinition(String json, HostDefinition host) throws IOException {
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
else if (n.equals("attachment")) {
while (jp.nextToken() != JsonToken.END_OBJECT) {
String field = jp.getCurrentName();
if (field.equals("id")) {
host.attachment = jp.getText();
} else if (field.equals("mac")) {
host.mac = jp.getText();
}
}
}
}
jp.close();
}
示例4: _testAsInt
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private void _testAsInt(int mode) throws Exception
{
final String input = "[ 1, -3, 4.98, true, false, null, \"-17\", \"foo\" ]";
JsonParser p = createParser(mode, input);
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertEquals(0, p.getValueAsLong());
assertEquals(9, p.getValueAsLong(9));
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(1, p.getValueAsLong());
assertEquals(1, p.getValueAsLong(-99));
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(-3, p.getValueAsLong());
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertEquals(4, p.getValueAsLong());
assertEquals(4, p.getValueAsLong(99));
assertToken(JsonToken.VALUE_TRUE, p.nextToken());
assertEquals(1, p.getValueAsLong());
assertToken(JsonToken.VALUE_FALSE, p.nextToken());
assertEquals(0, p.getValueAsLong());
assertToken(JsonToken.VALUE_NULL, p.nextToken());
assertEquals(0, p.getValueAsLong());
assertEquals(0, p.getValueAsLong(27));
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals(-17, p.getValueAsLong());
assertEquals(-17, p.getValueAsLong(3));
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals(0, p.getValueAsLong());
assertEquals(9, p.getValueAsLong(9));
assertToken(JsonToken.END_ARRAY, p.nextToken());
assertEquals(0, p.getValueAsLong());
assertEquals(9, p.getValueAsLong(9));
p.close();
}
示例5: _testAsBoolean
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private void _testAsBoolean(int mode) throws Exception
{
final String input = "[ true, false, null, 1, 0, \"true\", \"false\", \"foo\" ]";
JsonParser p = createParser(mode, input);
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertEquals(false, p.getValueAsBoolean());
assertEquals(true, p.getValueAsBoolean(true));
assertToken(JsonToken.VALUE_TRUE, p.nextToken());
assertEquals(true, p.getValueAsBoolean());
assertToken(JsonToken.VALUE_FALSE, p.nextToken());
assertEquals(false, p.getValueAsBoolean());
assertToken(JsonToken.VALUE_NULL, p.nextToken());
assertEquals(false, p.getValueAsBoolean());
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(1, p.getIntValue());
assertEquals(true, p.getValueAsBoolean());
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(0, p.getIntValue());
assertEquals(false, p.getValueAsBoolean());
assertToken(JsonToken.VALUE_STRING, p.nextToken()); // "true"
assertEquals(true, p.getValueAsBoolean());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals(false, p.getValueAsBoolean());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals(false, p.getValueAsBoolean());
assertToken(JsonToken.END_ARRAY, p.nextToken());
assertEquals(false, p.getValueAsBoolean());
assertEquals(true, p.getValueAsBoolean(true));
p.close();
}
示例6: jsonToHostDefinition
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
protected void jsonToHostDefinition(String json, HostDefinition host) throws IOException {
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
else if (n.equals("attachment")) {
while (jp.nextToken() != JsonToken.END_OBJECT) {
String field = jp.getCurrentName();
if (field.equals("id")) {
host.attachment = jp.getText();
} else if (field.equals("mac")) {
host.mac = jp.getText();
}
}
}
}
jp.close();
}
示例7: testToIntCoercion
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public void testToIntCoercion() throws Exception
{
for (int mode : ALL_STREAMING_MODES) {
JsonParser p;
// long->int
p = createParser(mode, "1");
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(1L, p.getLongValue());
assertEquals(1, p.getIntValue());
p.close();
// BigInteger->int
p = createParser(mode, "10");
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(BigInteger.TEN, p.getBigIntegerValue());
assertEquals(10, p.getIntValue());
p.close();
// double->int
p = createParser(mode, "2");
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(2.0, p.getDoubleValue());
assertEquals(2, p.getIntValue());
p.close();
// BigDecimal->int
p = createParser(mode, "10");
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(BigDecimal.TEN, p.getDecimalValue());
assertEquals(10, p.getIntValue());
p.close();
}
}
示例8: testToLongCoercion
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public void testToLongCoercion() throws Exception
{
for (int mode : ALL_STREAMING_MODES) {
JsonParser p;
// int->long
p = createParser(mode, "1");
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(1, p.getIntValue());
assertEquals(1L, p.getLongValue());
p.close();
// BigInteger->long
long biggish = 12345678901L;
p = createParser(mode, String.valueOf(biggish));
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(BigInteger.valueOf(biggish), p.getBigIntegerValue());
assertEquals(biggish, p.getLongValue());
p.close();
// double->long
p = createParser(mode, "2");
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(2.0, p.getDoubleValue());
assertEquals(2L, p.getLongValue());
p.close();
// BigDecimal->long
p = createParser(mode, "10");
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(BigDecimal.TEN, p.getDecimalValue());
assertEquals(10, p.getLongValue());
p.close();
}
}
示例9: testToBigIntegerCoercion
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public void testToBigIntegerCoercion() throws Exception
{
for (int mode : ALL_STREAMING_MODES) {
JsonParser p;
p = createParser(mode, "1");
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
// int to BigInteger
assertEquals(1, p.getIntValue());
assertEquals(BigInteger.ONE, p.getBigIntegerValue());
p.close();
p = createParser(mode, "2.0");
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
// double to BigInteger
assertEquals(2.0, p.getDoubleValue());
assertEquals(BigInteger.valueOf(2L), p.getBigIntegerValue());
p.close();
p = createParser(mode, String.valueOf(Long.MAX_VALUE));
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
// long to BigInteger
assertEquals(Long.MAX_VALUE, p.getLongValue());
assertEquals(BigInteger.valueOf(Long.MAX_VALUE), p.getBigIntegerValue());
p.close();
p = createParser(mode, " 200.0");
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
// BigDecimal to BigInteger
assertEquals(new BigDecimal("200.0"), p.getDecimalValue());
assertEquals(BigInteger.valueOf(200L), p.getBigIntegerValue());
p.close();
}
}
示例10: _testMangledNumbersInt
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private void _testMangledNumbersInt(int mode) throws Exception
{
JsonParser p = createParser(mode, "123true");
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: "+t);
} catch (JsonParseException e) {
verifyException(e, "expected space");
}
p.close();
}
示例11: _testMangledNumbersFloat
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private void _testMangledNumbersFloat(int mode) throws Exception
{
// Also test with floats
JsonParser p = createParser(mode, "1.5false");
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: "+t);
} catch (JsonParseException e) {
verifyException(e, "expected space");
}
p.close();
}
示例12: jsonToNetworkDefinition
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
protected void jsonToNetworkDefinition(String json, NetworkDefinition network) throws IOException {
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
else if (n.equals("network")) {
while (jp.nextToken() != JsonToken.END_OBJECT) {
String field = jp.getCurrentName();
if (field == null) continue;
if (field.equals("name")) {
network.name = jp.getText();
} else if (field.equals("gateway")) {
String gw = jp.getText();
if ((gw != null) && (!gw.equals("null")))
network.gateway = gw;
} else if (field.equals("id")) {
network.guid = jp.getText();
} else {
log.warn("Unrecognized field {} in " +
"parsing network definition",
jp.getText());
}
}
}
}
jp.close();
}
示例13: jsonToPool
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
protected LBPool jsonToPool(String json) throws IOException {
if (json==null) return null;
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
LBPool pool = new LBPool();
try {
jp = f.createParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n.equals("id")) {
pool.id = jp.getText();
continue;
}
if (n.equals("tenant_id")) {
pool.tenantId = jp.getText();
continue;
}
if (n.equals("name")) {
pool.name = jp.getText();
continue;
}
if (n.equals("network_id")) {
pool.netId = jp.getText();
continue;
}
if (n.equals("lb_method")) {
pool.lbMethod = Short.parseShort(jp.getText());
continue;
}
if (n.equals("protocol")) {
String tmp = jp.getText();
if (tmp.equalsIgnoreCase("TCP")) {
pool.protocol = (byte) IpProtocol.TCP.getIpProtocolNumber();
} else if (tmp.equalsIgnoreCase("UDP")) {
pool.protocol = (byte) IpProtocol.UDP.getIpProtocolNumber();
} else if (tmp.equalsIgnoreCase("ICMP")) {
pool.protocol = (byte) IpProtocol.ICMP.getIpProtocolNumber();
}
continue;
}
if (n.equals("vip_id")) {
pool.vipId = jp.getText();
continue;
}
log.warn("Unrecognized field {} in " +
"parsing Pools",
jp.getText());
}
jp.close();
return pool;
}
示例14: parse
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public static <T, U> Map<T, U> parse(byte[] json) throws IOException {
JsonParser parser = DEFAULT_MAPPER.getFactory().createParser(json);
Map<T, U> result = _parse(parser);
parser.close();
return result;
}
示例15: jsonToVip
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
protected LBVip jsonToVip(String json) throws IOException {
if (json==null) return null;
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
LBVip vip = new LBVip();
try {
jp = f.createJsonParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n.equals("id")) {
vip.id = jp.getText();
continue;
}
if (n.equals("tenant_id")) {
vip.tenantId = jp.getText();
continue;
}
if (n.equals("name")) {
vip.name = jp.getText();
continue;
}
if (n.equals("network_id")) {
vip.netId = jp.getText();
continue;
}
if (n.equals("protocol")) {
String tmp = jp.getText();
if (tmp.equalsIgnoreCase("TCP")) {
vip.protocol = (byte) IpProtocol.TCP.getIpProtocolNumber();
} else if (tmp.equalsIgnoreCase("UDP")) {
vip.protocol = (byte) IpProtocol.UDP.getIpProtocolNumber();
} else if (tmp.equalsIgnoreCase("ICMP")) {
vip.protocol = (byte) IpProtocol.ICMP.getIpProtocolNumber();
}
continue;
}
if (n.equals("address")) {
vip.address = IPv4.toIPv4Address(jp.getText());
continue;
}
if (n.equals("port")) {
vip.port = Short.parseShort(jp.getText());
continue;
}
if (n.equals("pool_id")) {
vip.pools.add(jp.getText());
continue;
}
log.warn("Unrecognized field {} in " +
"parsing Vips",
jp.getText());
}
jp.close();
return vip;
}