javax.json.stream.JsonParser.getLocation()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中javax.json.stream.JsonParser.getLocation()方法的一些代码示例,展示了JsonParser.getLocation()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonParser.getLocation()方法的具体详情如下:
包路径:javax.json.stream.JsonParser
类名称:JsonParser
方法名:getLocation

JsonParser.getLocation介绍

[英]Return the location that corresponds to the parser's current state in the JSON input source. The location information is only valid in the current parser state (or until the parser is advanced to a next state).
[中]返回与JSON输入源中解析器的当前状态相对应的位置。位置信息仅在当前解析器状态下有效(或者直到解析器进入下一个状态)。

代码示例

代码示例来源:origin: org.apache.johnzon/johnzon-core

@Override
public JsonLocation getLocation() {
  return jsonParser.getLocation();
}

代码示例来源:origin: org.eclipse/yasson

@Override
public JsonLocation getLocation() {
  return jsonParser.getLocation();
}

代码示例来源:origin: apache/johnzon

@Override
public JsonLocation getLocation() {
  return jsonParser.getLocation();
}

代码示例来源:origin: dcm4che/dcm4che

public JsonLocation getLocation() {
  return parser.getLocation();
}

代码示例来源:origin: org.dcm4che/dcm4che-conf-json

public JsonLocation getLocation() {
  return parser.getLocation();
}

代码示例来源:origin: dcm4che/dcm4che

private void expect(Event expected) {
  if (this.event != expected)
    throw new JsonParsingException("Unexpected " + event + ", expected " + expected, parser.getLocation());
}

代码示例来源:origin: dcm4che/dcm4che

public void expect(JsonParser.Event expected) {
  if (this.event != expected)
    throw new JsonParsingException("Unexpected " + event + ", expected " + expected, parser.getLocation());
}

代码示例来源:origin: org.dcm4che/dcm4che-conf-json

public void expect(JsonParser.Event expected) {
  if (this.event != expected)
    throw new JsonParsingException("Unexpected " + event + ", expected " + expected, parser.getLocation());
}

代码示例来源:origin: beckchr/staxon

@Override
public int getLineNumber() {
  return (int)parser.getLocation().getLineNumber();
}

代码示例来源:origin: beckchr/staxon

@Override
public int getCharacterOffset() {
  return (int)parser.getLocation().getStreamOffset();
}

代码示例来源:origin: beckchr/staxon

@Override
public int getColumnNumber() {
  return (int)parser.getLocation().getColumnNumber();
}

代码示例来源:origin: dcm4che/dcm4che

public boolean booleanValue() {
  switch (next()) {
    case VALUE_FALSE:
      return false;
    case VALUE_TRUE:
      return true;
  }
  throw new JsonParsingException("Unexpected " + event
      + ", expected VALUE_FALSE or VALUE_TRUE", parser.getLocation());
}

代码示例来源:origin: org.dcm4che/dcm4che-conf-json

public boolean booleanValue() {
  switch (next()) {
    case VALUE_FALSE:
      return false;
    case VALUE_TRUE:
      return true;
  }
  throw new JsonParsingException("Unexpected " + event
      + ", expected VALUE_FALSE or VALUE_TRUE", parser.getLocation());
}

代码示例来源:origin: dcm4che/dcm4che

private List<Object> readDataFragments() {
  ArrayList<Object> list = new ArrayList<>();
  next();
  expect(Event.START_ARRAY);
  while (next() != Event.END_ARRAY) {
    switch (event) {
      case START_OBJECT:
        list.add(readDataFragment());
        break;
      case VALUE_NULL:
        list.add(null);
        break;
      default:
        throw new JsonParsingException("Unexpected " + event, parser.getLocation());
    }
  }
  return list;
}

代码示例来源:origin: org.opendaylight.aaa/aaa-authn-idpmapping

private List<Object> loadJsonArray(JsonParser parser, Event event) {
  List<Object> list = new ArrayList<Object>();
  if (event != Event.START_ARRAY) {
    JsonLocation location = parser.getLocation();
    throw new IllegalStateException(
        String.format(
            "expected JSON parsing event to be START_ARRAY, not %s location(line=%d column=%d offset=%d)",
            event, location.getLineNumber(), location.getColumnNumber(),
            location.getStreamOffset()));
  }
  event = parser.next(); // consume START_ARRAY
  while (event != Event.END_ARRAY) {
    Object obj;
    obj = loadJsonItem(parser, event);
    list.add(obj);
    event = parser.next(); // next array item or END_ARRAY
  }
  return list;
}

代码示例来源:origin: dcm4che/dcm4che

throw new JsonParsingException("Unexpected \"" + getString()
    + "\", expected \"Alphabetic\" or \"Ideographic\""
    + " or \"Phonetic\"", parser.getLocation());

代码示例来源:origin: dcm4che/dcm4che

private List<Object> readValues() {
  ArrayList<Object> list = new ArrayList<>();
  next();
  expect(Event.START_ARRAY);
  while (next() != Event.END_ARRAY) {
    switch (event) {
      case START_OBJECT:
        list.add(readItemOrPersonName());
        break;
      case VALUE_STRING:
        list.add(parser.getString());
        break;
      case VALUE_NUMBER:
        list.add(parser.getBigDecimal());
        break;
      case VALUE_NULL:
        list.add(null);
        break;
      default:
        throw new JsonParsingException("Unexpected " + event, parser.getLocation());
    }
  }
  return list;
}

代码示例来源:origin: org.opendaylight.aaa/aaa-authn-idpmapping

private Map<String, Object> loadJsonObject(JsonParser parser, Event event) {
  Map<String, Object> map = new LinkedHashMap<String, Object>();
  if (event != Event.START_OBJECT) {
    JsonLocation location = parser.getLocation();
    throw new IllegalStateException(String.format(
        "expected JSON parsing event to be START_OBJECT, not %s, ",
        "location(line=%d column=%d offset=%d)", event, location.getLineNumber(),
        location.getColumnNumber(), location.getStreamOffset()));
  }
  event = parser.next(); // consume START_OBJECT
  while (event != Event.END_OBJECT) {
    if (event == Event.KEY_NAME) {
      String key;
      Object value;
      key = parser.getString();
      event = parser.next(); // consume key
      value = loadJsonItem(parser, event);
      map.put(key, value);
    } else {
      JsonLocation location = parser.getLocation();
      throw new IllegalStateException(
          String.format(
              "expected JSON parsing event to be KEY_NAME, not %s, location(line=%d column=%d offset=%d)",
              event, location.getLineNumber(), location.getColumnNumber(),
              location.getStreamOffset()));
    }
    event = parser.next(); // next key or END_OBJECT
  }
  return map;
}

代码示例来源:origin: org.eclipse/yasson

/**
 * Get root value event, either for new deserialization process, or deserialization sub-process invoked from
 * custom user deserializer.
 */
private JsonParser.Event getRootEvent(JsonParser parser) {
  if (parser.getLocation().getStreamOffset() == 0) {
    return parser.next();
  }
  final JsonParser.Event lastEvent = ((JsonbParser) parser).getCurrentLevel().getLastEvent();
  return lastEvent == JsonParser.Event.KEY_NAME ? parser.next() : lastEvent;
}

代码示例来源:origin: dcm4che/dcm4che

private Object readDataFragment() {
  byte[] bytes = null;
  String bulkDataURI = null;
  while (next() == Event.KEY_NAME) {
    switch (getString()) {
      case "BulkDataURI":
        bulkDataURI = valueString();
        break;
      case "InlineBinary":
        bytes = readInlineBinary();
        break;
      default:
        throw new JsonParsingException("Unexpected \"" + getString()
            + "\", expected \"InlineBinary\""
            + " or \"BulkDataURI\"", parser.getLocation());
    }
  }
  expect(Event.END_OBJECT);
  return bulkDataURI != null && !skipBulkDataURI
      ? new BulkData(null, bulkDataURI, false)
      : bytes;
}

相关文章