本文整理匯總了Java中com.fasterxml.jackson.core.JsonParser.getCurrentName方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonParser.getCurrentName方法的具體用法?Java JsonParser.getCurrentName怎麽用?Java JsonParser.getCurrentName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.fasterxml.jackson.core.JsonParser
的用法示例。
在下文中一共展示了JsonParser.getCurrentName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parse
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public ExternalModel parse(JsonParser jsonParser) throws IOException {
ExternalModel instance = new ExternalModel();
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
jsonParser.skipChildren();
return null;
}
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jsonParser.getCurrentName();
jsonParser.nextToken();
parseField(instance, fieldName, jsonParser);
jsonParser.skipChildren();
}
return instance;
}
示例2: parseFieldName
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
static void parseFieldName(JsonParser parser, JsonParsingContext context) throws IOException {
String fieldName = parser.getCurrentName();
switch (fieldName) {
case "offset":
context.offset = parser.nextIntValue(-1);
context.doubleValues = null;
context.stringValues = null;
break;
case "uncompressedLength":
context.uncompressedLength = parser.nextIntValue(-1);
break;
case "stepLengths":
context.stepLengths = new TIntArrayList();
context.valuesOrLengthArray = true;
break;
case "values":
case "stepValues":
context.valuesOrLengthArray = true;
break;
default:
break;
}
}
示例3: deserialize
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public PostContingencyResult deserialize(JsonParser parser, DeserializationContext deserializationContext) throws IOException {
Contingency contingency = null;
LimitViolationsResult limitViolationsResult = null;
while (parser.nextToken() != JsonToken.END_OBJECT) {
switch (parser.getCurrentName()) {
case "contingency":
parser.nextToken();
contingency = parser.readValueAs(Contingency.class);
break;
case "limitViolationsResult":
parser.nextToken();
limitViolationsResult = parser.readValueAs(LimitViolationsResult.class);
break;
default:
throw new AssertionError("Unexpected field: " + parser.getCurrentName());
}
}
return new PostContingencyResult(contingency, limitViolationsResult);
}
示例4: parse
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public LowerCaseNamingPolicyModel parse(JsonParser jsonParser) throws IOException {
LowerCaseNamingPolicyModel instance = new LowerCaseNamingPolicyModel();
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
jsonParser.skipChildren();
return null;
}
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jsonParser.getCurrentName();
jsonParser.nextToken();
parseField(instance, fieldName, jsonParser);
jsonParser.skipChildren();
}
return instance;
}
示例5: parse
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public PrivateFieldModel parse(JsonParser jsonParser) throws IOException {
PrivateFieldModel instance = new PrivateFieldModel();
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
jsonParser.skipChildren();
return null;
}
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jsonParser.getCurrentName();
jsonParser.nextToken();
parseField(instance, fieldName, jsonParser);
jsonParser.skipChildren();
}
return instance;
}
示例6: parse
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public NestedCollectionModel parse(JsonParser jsonParser) throws IOException {
NestedCollectionModel instance = new NestedCollectionModel();
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
jsonParser.skipChildren();
return null;
}
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jsonParser.getCurrentName();
jsonParser.nextToken();
parseField(instance, fieldName, jsonParser);
jsonParser.skipChildren();
}
return instance;
}
示例7: parse
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public SimpleCollectionModel parse(JsonParser jsonParser) throws IOException {
SimpleCollectionModel instance = new SimpleCollectionModel();
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
jsonParser.skipChildren();
return null;
}
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jsonParser.getCurrentName();
jsonParser.nextToken();
parseField(instance, fieldName, jsonParser);
jsonParser.skipChildren();
}
return instance;
}
示例8: jsonExtractSubnetMask
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的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.createParser(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;
}
示例9: parsePersons
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public void parsePersons(String filename) {
try {
JsonFactory jsonfactory = new JsonFactory();
File source = new File(filename);
JsonParser parser = jsonfactory.createParser(source);
while (parser.nextToken() != JsonToken.END_OBJECT) {
String token = parser.getCurrentName();
if ("persons".equals(token)) {
out.println("Persons found");
JsonToken jsonToken = parser.nextToken();
jsonToken = parser.nextToken();
token = parser.getCurrentName();
out.println("Next token is " + token);
if ("groupname".equals(token)) {
parser.nextToken();
String groupname = parser.getText();
out.println("Group : " + groupname);
parser.nextToken();
token = parser.getCurrentName();
if ("person".equals(token)) {
out.println("Found person");
parsePerson(parser);
}
}
}
}
parser.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
示例10: processToken
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private JsonToken processToken(JsonToken curToken, JsonParser parser, JsonGenerator jgen)
throws IOException {
if (curToken.isStructEnd()) {
// this is our escape and base case.
return curToken;
}
if (curToken.isStructStart()) {
processStructStart(curToken, jgen);
JsonToken token = processToken(parser.nextToken(), parser, jgen);
while (!token.isStructEnd()) {
token = processToken(token, parser, jgen);
}
processStructEnd(token, jgen);
return parser.nextToken();
}
if (curToken.id() == JsonTokenId.ID_FIELD_NAME) {
String currentName = parser.getCurrentName();
if (isFiltered && filters.containsKey(parser.getCurrentName())) {
jgen.writeFieldName(currentName);
// perform filtering.
return filters.get(parser.getCurrentName()).processToken(parser.nextToken(), parser, jgen);
} else if (!isFiltered) {
jgen.writeFieldName(currentName);
return processToken(parser.nextToken(), parser, jgen);
} else {
parser.nextToken();
parser.skipChildren();
return processToken(parser.nextToken(), parser, jgen);
}
} else if (curToken.isScalarValue()) {
processValue(curToken, parser, jgen);
return parser.nextToken();
} else {
LOGGER.error(
"Unable to process the token {} with name {}.", curToken, parser.getCurrentName());
throw new RuntimeException(
"Unable to process the token " + curToken + " with name" + parser.getCurrentName());
}
}
示例11: deserialize
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public NodeDependency deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
String name = null;
NodeInfo nodeInfo = null;
JsonToken token;
while ((token = jsonParser.nextToken()) != null) {
if (token == JsonToken.END_OBJECT) {
break;
} else if (token == JsonToken.FIELD_NAME) {
switch (jsonParser.getCurrentName()) {
case "name":
jsonParser.nextToken();
name = jsonParser.getValueAsString();
break;
case "nodeInfo":
nodeInfo = new NodeInfoJsonDeserializer().deserialize(jsonParser, deserializationContext);
break;
default:
throw new AssertionError("Unexpected field: " + jsonParser.getCurrentName());
}
}
}
if (name == null || nodeInfo == null) {
throw new IllegalStateException("Inconsistent node dependency json");
}
return new NodeDependency(name, nodeInfo);
}
示例12: deserialize
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public LimitViolationsResult deserialize(JsonParser parser, DeserializationContext deserializationContext) throws IOException {
boolean comutationOk = false;
List<LimitViolation> limitViolations = Collections.emptyList();
List<String> actionsTaken = Collections.emptyList();
while (parser.nextToken() != JsonToken.END_OBJECT) {
switch (parser.getCurrentName()) {
case "computationOk":
comutationOk = parser.nextBooleanValue();
break;
case "limitViolations":
parser.nextToken();
limitViolations = parser.readValueAs(new TypeReference<ArrayList<LimitViolation>>() {
});
break;
case "actionsTaken":
parser.nextToken();
actionsTaken = parser.readValueAs(new TypeReference<ArrayList<String>>() {
});
break;
default:
throw new AssertionError("Unexpected field: " + parser.getCurrentName());
}
}
return new LimitViolationsResult(comutationOk, limitViolations, actionsTaken);
}
示例13: readDatabase
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
long readDatabase(InputStream stream) throws IOException {
long timestamp = 0;
numeriche = new HashMap<>();
timestamp = System.currentTimeMillis();
JsonFactory jsonFactory = new JsonFactory(); // or, for data binding, org.codehaus.jackson.mapper.MappingJsonFactory
JsonParser jp = jsonFactory.createParser(stream); // or URL, Stream, Reader, String, byte[]
jp.nextToken(); // will return JsonToken.START_OBJECT (verify?)
// passo a leggere il database
String fieldName;
if (jp.nextToken() == JsonToken.FIELD_NAME) {
fieldName = jp.getCurrentName();
jp.nextToken(); // START_OBJECT INIZIO di un nuovo oggetto database
// Passo al campo nome
while (jp.nextToken() == JsonToken.FIELD_NAME) {
fieldName = jp.getCurrentName();
jp.nextToken(); // Vado al valore
if ("name".equals(fieldName)) {
System.out.println("Database Name:" + jp.getValueAsString());
} else if ("tables".equals(fieldName)) {
while (jp.nextToken() != JsonToken.END_ARRAY) {
readTable(jp);
}
}
}
}
jp.close();
long duration = System.currentTimeMillis() - timestamp;
return duration;
}
示例14: parseFieldName
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private static void parseFieldName(JsonParser jsonParser, JsonParsingContext parsingContext) throws IOException {
switch (jsonParser.getCurrentName()) {
case NodeGenericMetadataJsonSerializer.TYPE:
jsonParser.nextToken();
parsingContext.type = jsonParser.getValueAsString();
break;
case NodeGenericMetadataJsonSerializer.NAME:
jsonParser.nextToken();
parsingContext.name = jsonParser.getValueAsString();
break;
case NodeGenericMetadataJsonSerializer.VALUE:
Objects.requireNonNull(parsingContext.name);
Objects.requireNonNull(parsingContext.type);
jsonParser.nextToken();
switch (parsingContext.type) {
case NodeGenericMetadataJsonSerializer.STRING:
parsingContext.metadata.setString(parsingContext.name, jsonParser.getValueAsString());
break;
case NodeGenericMetadataJsonSerializer.DOUBLE:
parsingContext.metadata.setDouble(parsingContext.name, jsonParser.getValueAsDouble());
break;
case NodeGenericMetadataJsonSerializer.INT:
parsingContext.metadata.setInt(parsingContext.name, jsonParser.getValueAsInt());
break;
case NodeGenericMetadataJsonSerializer.BOOLEAN:
parsingContext.metadata.setBoolean(parsingContext.name, jsonParser.getValueAsBoolean());
break;
default:
throw new AssertionError("Unexpected metadata type " + parsingContext.type);
}
break;
default:
throw new AssertionError("Unexpected field: " + jsonParser.getCurrentName());
}
}
示例15: 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();
}
}