本文整理汇总了Java中com.fasterxml.jackson.core.JsonToken.FIELD_NAME属性的典型用法代码示例。如果您正苦于以下问题:Java JsonToken.FIELD_NAME属性的具体用法?Java JsonToken.FIELD_NAME怎么用?Java JsonToken.FIELD_NAME使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.fasterxml.jackson.core.JsonToken
的用法示例。
在下文中一共展示了JsonToken.FIELD_NAME属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readRecord
Map<String, Object> readRecord(JsonParser jp) throws IOException {
Map<String, Object> record = new HashMap<>();
String fielName = "";
Object value;
JsonToken token;
while((token = jp.nextToken()) != JsonToken.END_OBJECT) {
if (token == JsonToken.FIELD_NAME) {
fielName = jp.getCurrentName();
} else if (token == JsonToken.VALUE_STRING) {
value = jp.getValueAsString();
record.put(fielName, value);
} else if (token == JsonToken.VALUE_NUMBER_INT) {
value = jp.getValueAsLong();
record.put(fielName, value);
}
}
//System.out.println(record.toString());
return record;
}
示例2: deserialize
@Override
public List<IBaseSegmentDTO> deserialize(InputStream stream) throws WaySegmentDeserializationException {
try {
JsonParser jp = jsonFactory.createParser(stream);
List<IBaseSegmentDTO> segments = new ArrayList<IBaseSegmentDTO>();
JsonToken token = jp.nextToken();
ISegmentAdapter<IBaseSegmentDTO, T> adapter = null;
while(!jp.isClosed()){
token = jp.nextToken();
// extract type of segments. its encoded as the name of the array field holding the segments
if (jp.getCurrentToken() == JsonToken.FIELD_NAME) {
String segmentType = jp.getCurrentName();
adapter = this.getAndRegisterDeserializers(segmentType);
}
else if(token != null && token != JsonToken.END_ARRAY && token != JsonToken.END_OBJECT) {
segments.add(processSegment(jp, adapter));
}
}
log.info("parsed: " + segments.size() + " segments");
return segments;
} catch (Exception e) {
throw new WaySegmentDeserializationException(e.getMessage(),e);
}
}
示例3: deserialize
@Override
public I18NStrings deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
JsonProcessingException
{
Map<String, LanguageString> strings = Maps.newHashMap();
JsonToken currentToken = jp.getCurrentToken();
if( currentToken != JsonToken.START_OBJECT )
{
throw new JsonParseException("Must be an object", jp.getCurrentLocation());
}
while( jp.nextToken() == JsonToken.FIELD_NAME )
{
String textValue = jp.nextTextValue();
LanguageBundle tempBundle = LangUtils.createTempLangugageBundle(null, textValue);
LanguageString tempLangString = LangUtils.createLanguageString(tempBundle, CurrentLocale.getLocale(),
textValue);
strings.put(jp.getCurrentName(), tempLangString);
}
return new SimpleI18NStrings(strings);
}
示例4: parseGroup
public Group parseGroup() throws Exception {
Group group = new Group();
accept(JsonToken.START_OBJECT);
for (;;) {
JsonToken tok = parser.getCurrentToken();
if (tok == JsonToken.END_OBJECT) {
break;
}
if (tok == JsonToken.FIELD_NAME) {
String name = parser.getCurrentName();
tok = parser.nextToken();
if ("name" == name) {
group.setName(acceptString(tok));
} else if ("description" == name) {
group.setDescription(acceptString(tok));
} else if ("companies" == name) {
parseCompany(group.getCompanies());
} else {
throw new RuntimeException("not match property : " + name);
}
}
}
accept(JsonToken.END_OBJECT);
return group;
}
示例5: jsonToHostDefinition
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();
}
示例6: parseJson
static List<TimeSeries> parseJson(JsonParser parser, boolean single) {
Objects.requireNonNull(parser);
List<TimeSeries> timeSeriesList = new ArrayList<>();
try {
TimeSeriesMetadata metadata = null;
JsonToken token;
while ((token = parser.nextToken()) != null) {
if (token == JsonToken.FIELD_NAME) {
String fieldName = parser.getCurrentName();
switch (fieldName) {
case "metadata":
metadata = TimeSeriesMetadata.parseJson(parser);
break;
case "chunks":
if (metadata == null) {
throw new AssertionError("metadata is null");
}
parseChunks(parser, metadata, timeSeriesList);
metadata = null;
break;
default:
break;
}
} else if (token == JsonToken.END_OBJECT && single) {
break;
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return timeSeriesList;
}
示例7: deserialize
@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);
}
示例8: getEntryNameFromJson
/**
* 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;
}
示例9: readDatabase
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;
}
示例10: jsonToHostDefinition
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();
}
示例11: loadPart
private static Part loadPart(int index, JsonParser parser, double location) throws IOException {
if (parser.nextToken() != JsonToken.FIELD_NAME) {
throw new IOException( "Field name expected.");
}
if (!Objects.equals(parser.getCurrentName(), "length")) {
throw new IOException("length field expected.");
}
parser.nextToken();
double length = parser.getDoubleValue();
if (parser.nextToken() != JsonToken.FIELD_NAME) {
throw new IOException("Field name expected.");
}
if (!Objects.equals(parser.getCurrentName(), "type")) {
throw new IOException("type field expected.");
}
parser.nextToken();
String val = parser.getText();
Part.TYPE type;
if (Objects.equals(val, "s")) {
type = Part.TYPE.STRAIGHT;
} else if (Objects.equals(val, "c")) {
type = Part.TYPE.CURVED;
} else {
throw new IOException("Invalid part type detected.");
}
if (parser.nextToken() != JsonToken.END_OBJECT) {
throw new IOException("Expected object to end.");
}
return new Part(index, type, length, location);
}
示例12: hasBinary
boolean hasBinary() throws JsonParseException, IOException {
JsonToken token = parser.nextToken();
return token == JsonToken.FIELD_NAME && parser.getText().equals(ExtendedTypeName.BINARY);
}
示例13: handle
void handle(final Map<String, ValueMetadata> colMetadataMap) throws IOException {
String fieldName;
ValueMetadata columnMetadata;
JSonConverter converter;
Value value;
// Create a new record
mCurrentRecord = new Record();
while (mJp.nextToken() != JsonToken.END_OBJECT) {
if (mJp.getCurrentToken() == JsonToken.FIELD_NAME) {
fieldName = mJp.getCurrentName();
// Get column metadata
if (!colMetadataMap.containsKey(fieldName)){
throw new IOException("Unable to find columns metadata for columns " + fieldName);
}
columnMetadata = colMetadataMap.get(fieldName);
// Build the data converter and convert
converter = JSonConverterFactory.buildConverter(columnMetadata);
value = converter.jsonToColumnValue(mJp, columnMetadata);
mCurrentRecord.add(value);
}
if (mJp.getCurrentToken() == JsonToken.END_ARRAY) {
// End Array also no records
break;
}
}
// Go to next token, only if not the end of records
if (mJp.getCurrentToken() != JsonToken.END_ARRAY) {
mJp.nextToken();
}
if (mJp.getCurrentToken() == JsonToken.START_OBJECT) {
// The current token is start of object -> new record no change state required
return;
} else if (mJp.getCurrentToken() == JsonToken.END_ARRAY) {
// The current token is end of array -> end of record, end of table, end of database
// Consume end of object of current table
mJp.nextToken();
if(mJp.getCurrentToken() != JsonToken.END_OBJECT){
throw new IOException("Unable to read end of table expected end of object line :" + mJp.getCurrentLocation().getLineNr());
}
// Consume other token to dete end of database
// if START_OBJECT -> new TableToSync
// if END_ARRAY -> end of database
mJp.nextToken();
if (mJp.getCurrentToken() == JsonToken.START_OBJECT) {
mState = new StartTableState();
} else if (mJp.getCurrentToken() == JsonToken.END_ARRAY) {
mState = new EndState();
} else {
throw new IOException("Unable to read start of table expected { or ] line:" + mJp.getCurrentLocation().getLineNr());
}
} else {
throw new IOException("Unexpected token " + mJp.getCurrentToken() + " line:" + mJp.getCurrentLocation().getLineNr());
}
}
示例14: parseEmployee
private Employee parseEmployee() throws Exception {
accept(JsonToken.START_OBJECT);
Employee emp = new Employee();
for (;;) {
JsonToken tok = parser.getCurrentToken();
if (tok == JsonToken.END_OBJECT) {
break;
}
if (tok == JsonToken.FIELD_NAME) {
String name = parser.getCurrentName();
tok = parser.nextToken();
if ("name" == name) {
emp.setName(acceptString(tok));
} else if ("description" == name) {
emp.setDescription(acceptString(tok));
} else if ("number" == name) {
emp.setNumber(acceptString(tok));
} else if ("id" == name) {
emp.setId(acceptLong(tok));
} else if ("age" == name) {
emp.setAge(acceptInteger(tok));
} else if ("salary" == name) {
emp.setSalary(acceptBigDecimal(tok));
} else if ("birthdate" == name) {
emp.setBirthdate(new Date(acceptLong(tok)));
} else if ("badboy" == name) {
emp.setBadboy(acceptBoolean(tok));
} else {
throw new RuntimeException("not match property : " + name);
}
}
}
accept(JsonToken.END_OBJECT);
return emp;
}
示例15: jsonToVip
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;
}