本文整理汇总了Java中javax.json.stream.JsonParser.Event方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParser.Event方法的具体用法?Java JsonParser.Event怎么用?Java JsonParser.Event使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.stream.JsonParser
的用法示例。
在下文中一共展示了JsonParser.Event方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseJsonString
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
private static void parseJsonString() {
JsonParser parser = Json.createParser(new StringReader(JSON));
while (parser.hasNext()) {
JsonParser.Event event = parser.next();
switch (event) {
case START_ARRAY:
case END_ARRAY:
case START_OBJECT:
case END_OBJECT:
case VALUE_FALSE:
case VALUE_NULL:
case VALUE_TRUE:
System.out.println(event.toString());
break;
case KEY_NAME:
System.out.print(event.toString() + " " + parser.getString() + " - ");
break;
case VALUE_STRING:
case VALUE_NUMBER:
System.out.println(event.toString() + " " + parser.getString());
break;
}
}
}
示例2: deserialize
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Override
public Book deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
Book book = null;
while (parser.hasNext()) {
JsonParser.Event event = parser.next();
if (event == JsonParser.Event.KEY_NAME) {
String className = parser.getString();
parser.next();
try {
book = ctx.deserialize(Class.forName(className).asSubclass(Book.class), parser);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
return book;
}
示例3: buildArray
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
private JsonArray buildArray(ArrayType type) {
ArrayContext context = new ArrayContext(this.transientValueProvider, this.builderFactory);
pushContext(context);
TypeSet itemTypes = type.getItemTypes();
while (parser.hasNext()) {
JsonParser.Event event = parser.next();
if (event == JsonParser.Event.END_ARRAY) {
popContext();
return context.getArray();
} else {
context.nextItem();
readValue(event, itemTypes);
}
}
throw internalError();
}
示例4: retrieveValue
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
public String retrieveValue(final String key_to_find, final String json) {
JsonParser parser = Json.createParser(new StringReader(json));
while (parser.hasNext()) {
JsonParser.Event event = parser.next();
switch (event) {
case KEY_NAME:
if (parser.getString().equalsIgnoreCase(key_to_find)) {
event = parser.next();
if (event == VALUE_STRING || event == VALUE_NUMBER) {
return parser.getString();
}
}
break;
}
}
return null;
}
示例5: buildObject
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
private JsonObject buildObject(ObjectType objectType) {
ObjectContext context = new ObjectContext(this.transientValueProvider, this.builderFactory);
pushContext(context);
while (parser.hasNext()) {
JsonParser.Event e = parser.next();
if (e == JsonParser.Event.END_OBJECT) {
popContext();
return context.getObject();
} else if (e == JsonParser.Event.KEY_NAME) {
readProperty(objectType, context);
} else {
throw internalError();
}
}
throw internalError();
}
示例6: deserializeInternal
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void deserializeInternal(JsonbParser parser, Unmarshaller context) {
parserContext = moveToFirst(parser);
JsonParser.Event lastEvent = parserContext.getLastEvent();
final UserDeserializerParser userDeserializerParser = new UserDeserializerParser(parser);
try {
context.getJsonbContext().addProcessedType(deserializerBinding.getBindingType());
deserializerResult = (T) deserializerBinding.getJsonbDeserializer().deserialize(userDeserializerParser, context, getRuntimeType());
} finally {
context.getJsonbContext().removeProcessedType(deserializerBinding.getBindingType());
}
//Avoid moving parser to the end of the object, if deserializer was for one value only.
if (lastEvent == JsonParser.Event.START_ARRAY || lastEvent == JsonParser.Event.START_OBJECT) {
userDeserializerParser.advanceParserToEnd();
}
}
示例7: deserializeInternal
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
protected void deserializeInternal(JsonbParser parser, Unmarshaller context) {
parserContext = moveToFirst(parser);
while (parser.hasNext()) {
final JsonParser.Event event = parser.next();
switch (event) {
case START_OBJECT:
case START_ARRAY:
case VALUE_STRING:
case VALUE_NUMBER:
case VALUE_FALSE:
case VALUE_TRUE:
deserializeNext(parser, context);
break;
case KEY_NAME:
break;
case VALUE_NULL:
appendResult(null);
break;
case END_OBJECT:
case END_ARRAY:
return;
default:
throw new JsonbException(Messages.getMessage(MessageKeys.NOT_VALUE_TYPE, event));
}
}
}
示例8: deserialize
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Override
public JsonValue deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
final JsonParser.Event next = ((JsonbRiParser)parser).getLastEvent();
switch (next) {
case VALUE_TRUE:
return JsonValue.TRUE;
case VALUE_FALSE:
return JsonValue.FALSE;
case VALUE_NULL:
return JsonValue.NULL;
case VALUE_STRING:
case VALUE_NUMBER:
return parser.getValue();
default:
throw new JsonbException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Unknown JSON value: "+next));
}
}
示例9: deserialize
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Override
public String deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
while (parser.hasNext()) {
JsonParser.Event event = parser.next();
if (event == JsonParser.Event.KEY_NAME) {
String keyName = parser.getString();
if (keyName.equals("id")) {
return ctx.deserialize(String.class, parser);
}
}
parser.next();
}
return "";
}
示例10: testJsonParser
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testJsonParser() {
String key = "";
String value = "";
JsonParser parser = Json.createParser(JsonpTest.class.getResourceAsStream("/person.json"));
while (parser.hasNext()) {
JsonParser.Event e = parser.next();
System.out.print(e.name());
switch (e) {
case START_ARRAY:
if (key.equals("phoneNumbers")) {
parser.skipArray();
}
break;
case KEY_NAME:
key = parser.getString();
System.out.print(" - " + parser.getString());
break;
case VALUE_STRING:
System.out.print(" - " + parser.getString());
if ("name".equals(key)) {
value = parser.getString();
}
}
System.out.println();
}
assertEquals("Duke", value);
}
示例11: parseJson
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
public String parseJson() {
StringReader stringReader = new StringReader(jsonStr);
JsonParser jsonParser = Json.createParser(stringReader);
Map<String, Object> jsonMap = new HashMap<>();
String jsonKeyNm = null;
Object jsonVal = null;
while (jsonParser.hasNext()) {
JsonParser.Event event = jsonParser.next();
if (event.equals(Event.KEY_NAME)) {
jsonKeyNm = jsonParser.getString();
} else if (event.equals(Event.VALUE_STRING)) {
jsonVal = jsonParser.getString();
} else if (event.equals(Event.VALUE_NUMBER)) {
jsonVal = jsonParser.getInt();
}
jsonMap.put(jsonKeyNm, jsonVal);
}
person.setFirstName((String) jsonMap.get("firstName"));
person.setMiddleName((String) jsonMap.get("middleName"));
person.setLastName((String) jsonMap.get("lastName"));
person.setGender((String) jsonMap.get("gender"));
person.setAge((Integer) jsonMap.get("age"));
return "display_populated_obj";
}
开发者ID:PacktPublishing,项目名称:Java-EE-7-Development-with-NetBeans-8,代码行数:32,代码来源:JsonPStreamingApiBean.java
示例12: deserialize
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Override
public Crate deserialize(JsonParser jsonParser, DeserializationContext ctx, Type rtType) {
Crate crate = new Crate();
crate.crateStr = "abc";
crate.crateBigDec = new BigDecimal("123");
while (jsonParser.hasNext()) {
JsonParser.Event next = jsonParser.next();
if (next.equals(JsonParser.Event.KEY_NAME) && jsonParser.getString().equals("crateInner")) {
//invokes JSONB processing for a CrateInner as a root type with "shared" instance of JsonParser
crate.crateInner = ctx.deserialize(CrateInner.class, jsonParser);
continue;
}
if (next.equals(JsonParser.Event.KEY_NAME) && jsonParser.getString().equals("crateInnerList")) {
//invokes JSONB processing for a CrateInner as a root type with "shared" instance of JsonParser
crate.crateInnerList = ctx.deserialize(new TestTypeToken<ArrayList<CrateInner>>(){}.getType(), jsonParser);
continue;
}
if (next.equals(JsonParser.Event.KEY_NAME) && jsonParser.getString().equals("date")) {
//move to value
jsonParser.next();
//don't have context of processing here, no annotation customizations applied.
// crate.date = ctx.convertDefault(Date.class, jsonParser.getString());
ctx.deserialize(Date.class, jsonParser);
}
}
return crate;
}
示例13: moveTo
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Override
public void moveTo(JsonParser.Event required) {
if (!level.empty() && level.peek().getLastEvent() == required) {
return;
}
final Event next = next();
if (next == required) {
return;
}
throw new JsonbException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Event " + required + " not found." + getLastDataMsg()));
}
示例14: deserialize
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
public SimpleContainer[] deserialize(JsonParser jsonParser, DeserializationContext deserializationContext, Type type) {
List<SimpleContainer> containers = new ArrayList<>();
while (jsonParser.hasNext()) {
JsonParser.Event event = jsonParser.next();
if (event == JsonParser.Event.START_OBJECT) {
containers.add(deserializationContext.deserialize(new SimpleContainer(){}.getClass().getGenericSuperclass(), jsonParser));
}
if (event == JsonParser.Event.END_OBJECT) {
break;
}
}
return containers.toArray(new SimpleContainer[0]);
}
示例15: deserialize
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Override
public OptionalLong deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
final JsonParser.Event next = ((JsonbParser) parser).moveToValue();
if (next == JsonParser.Event.VALUE_NULL) {
return OptionalLong.empty();
}
return deserialize(parser.getString(), (Unmarshaller) ctx, rtType);
}