本文整理匯總了Java中com.fasterxml.jackson.databind.MappingJsonFactory.createJsonParser方法的典型用法代碼示例。如果您正苦於以下問題:Java MappingJsonFactory.createJsonParser方法的具體用法?Java MappingJsonFactory.createJsonParser怎麽用?Java MappingJsonFactory.createJsonParser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.fasterxml.jackson.databind.MappingJsonFactory
的用法示例。
在下文中一共展示了MappingJsonFactory.createJsonParser方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: jsonToHostDefinition
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的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();
}
示例2: getEntryNameFromJson
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的package包/類
/**
* Gets the entry name of a flow mod
* @param fmJson The OFFlowMod in a JSON representation
* @return The name of the OFFlowMod, null if not found
* @throws IOException If there was an error parsing the JSON
*/
public static String getEntryNameFromJson(String fmJson) throws IOException{
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(fmJson);
} 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 == StaticFlowEntryPusher.COLUMN_NAME)
return jp.getText();
}
return null;
}
示例3: jsonExtractSubnetMask
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的package包/類
/**
* Extracts subnet mask from a JSON string
* @param fmJson The JSON formatted string
* @return The subnet mask
* @throws IOException If there was an error parsing the JSON
*/
public static String jsonExtractSubnetMask(String fmJson) throws IOException {
String subnet_mask = "";
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(fmJson);
} 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 == "subnet-mask") {
subnet_mask = jp.getText();
break;
}
}
return subnet_mask;
}
示例4: getEntryNameFromJson
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的package包/類
/**
* Gets the entry name of a flow mod
* @param fmJson The OFFlowMod in a JSON representation
* @return The name of the OFFlowMod, null if not found
* @throws IOException If there was an error parsing the JSON
*/
public static String getEntryNameFromJson(String fmJson) throws IOException{
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(fmJson);
} 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 == "name")
return jp.getText();
}
return null;
}
示例5: jsonExtractSubnetMask
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的package包/類
/**
* Extracts subnet mask from a JSON string
* @param fmJson The JSON formatted string
* @return The subnet mask
* @throws IOException If there was an error parsing the JSON
*/
public static String jsonExtractSubnetMask(String fmJson) throws IOException {
String subnet_mask = "";
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(fmJson);
} 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 == "subnet-mask") {
subnet_mask = jp.getText();
break;
}
}
return subnet_mask;
}
示例6: getSwitchId
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的package包/類
private String getSwitchId(String fmJson) throws IOException {
System.out.println(fmJson);
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
String requestSwitch = "";
try {
jp = f.createJsonParser(fmJson);
} 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();
switch (n) {
case StaticFlowEntryPusher.COLUMN_SWITCH:
requestSwitch = jp.getText();
System.out.println(requestSwitch);
return requestSwitch;
}
}
return requestSwitch;
}
示例7: jsonToNetworkDefinition
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的package包/類
protected void jsonToNetworkDefinition(String json, NetworkDefinition network) 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("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();
}
示例8: jsonToVip
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的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;
}
示例9: jsonToPool
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的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.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")) {
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;
}
示例10: jsonToMember
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的package包/類
protected LBMember jsonToMember(String json) throws IOException {
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
LBMember member = new LBMember();
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")) {
member.id = jp.getText();
continue;
} else
if (n.equals("address")) {
member.address = IPv4.toIPv4Address(jp.getText());
continue;
} else
if (n.equals("port")) {
member.port = Short.parseShort(jp.getText());
continue;
} else
if (n.equals("connection_limit")) {
member.connectionLimit = Integer.parseInt(jp.getText());
continue;
} else
if (n.equals("admin_state")) {
member.adminState = Short.parseShort(jp.getText());
continue;
} else
if (n.equals("status")) {
member.status = Short.parseShort(jp.getText());
continue;
} else
if (n.equals("pool_id")) {
member.poolId = jp.getText();
continue;
}
log.warn("Unrecognized field {} in " +
"parsing Members",
jp.getText());
}
jp.close();
return member;
}
示例11: jsonToVip
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的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 = IPv4.PROTOCOL_TCP;
} else if (tmp.equalsIgnoreCase("UDP")) {
vip.protocol = IPv4.PROTOCOL_UDP;
} else if (tmp.equalsIgnoreCase("ICMP")) {
vip.protocol = IPv4.PROTOCOL_ICMP;
}
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;
}
示例12: jsonToPool
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的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.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")) {
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 = IPv4.PROTOCOL_TCP;
} else if (tmp.equalsIgnoreCase("UDP")) {
pool.protocol = IPv4.PROTOCOL_UDP;
} else if (tmp.equalsIgnoreCase("ICMP")) {
pool.protocol = IPv4.PROTOCOL_ICMP;
}
continue;
}
if (n.equals("vip_id")) {
pool.vipId = jp.getText();
continue;
}
log.warn("Unrecognized field {} in " +
"parsing Pools",
jp.getText());
}
jp.close();
return pool;
}
示例13: jsonToStorageEntry
import com.fasterxml.jackson.databind.MappingJsonFactory; //導入方法依賴的package包/類
/**
* Turns a JSON formatted Static Flow Pusher string into a storage entry
* Expects a string in JSON along the lines of:
* {
* "switch": "AA:BB:CC:DD:EE:FF:00:11",
* "name": "flow-mod-1",
* "cookie": "0",
* "priority": "32768",
* "ingress-port": "1",
* "actions": "output=2",
* }
* @param fmJson The JSON formatted static flow pusher entry
* @return The map of the storage entry
* @throws IOException If there was an error parsing the JSON
*/
public static Map<String, Object> jsonToStorageEntry(String fmJson) throws IOException {
Map<String, Object> entry = new HashMap<String, Object>();
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(fmJson);
} 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 == "name")
entry.put(StaticFlowEntryPusher.COLUMN_NAME, jp.getText());
else if (n == "switch")
entry.put(StaticFlowEntryPusher.COLUMN_SWITCH, jp.getText());
else if (n == "actions")
entry.put(StaticFlowEntryPusher.COLUMN_ACTIONS, jp.getText());
else if (n == "priority")
entry.put(StaticFlowEntryPusher.COLUMN_PRIORITY, jp.getText());
else if (n == "active")
entry.put(StaticFlowEntryPusher.COLUMN_ACTIVE, jp.getText());
else if (n == "wildcards")
entry.put(StaticFlowEntryPusher.COLUMN_WILDCARD, jp.getText());
else if (n == "ingress-port")
entry.put(StaticFlowEntryPusher.COLUMN_IN_PORT, jp.getText());
else if (n == "src-mac")
entry.put(StaticFlowEntryPusher.COLUMN_DL_SRC, jp.getText());
else if (n == "dst-mac")
entry.put(StaticFlowEntryPusher.COLUMN_DL_DST, jp.getText());
else if (n == "vlan-id")
entry.put(StaticFlowEntryPusher.COLUMN_DL_VLAN, jp.getText());
else if (n == "vlan-priority")
entry.put(StaticFlowEntryPusher.COLUMN_DL_VLAN_PCP, jp.getText());
else if (n == "ether-type")
entry.put(StaticFlowEntryPusher.COLUMN_DL_TYPE, jp.getText());
else if (n == "tos-bits")
entry.put(StaticFlowEntryPusher.COLUMN_NW_TOS, jp.getText());
else if (n == "protocol")
entry.put(StaticFlowEntryPusher.COLUMN_NW_PROTO, jp.getText());
else if (n == "src-ip")
entry.put(StaticFlowEntryPusher.COLUMN_NW_SRC, jp.getText());
else if (n == "dst-ip")
entry.put(StaticFlowEntryPusher.COLUMN_NW_DST, jp.getText());
else if (n == "src-port")
entry.put(StaticFlowEntryPusher.COLUMN_TP_SRC, jp.getText());
else if (n == "dst-port")
entry.put(StaticFlowEntryPusher.COLUMN_TP_DST, jp.getText());
}
return entry;
}