本文整理汇总了Java中com.google.gson.stream.JsonReader.skipValue方法的典型用法代码示例。如果您正苦于以下问题:Java JsonReader.skipValue方法的具体用法?Java JsonReader.skipValue怎么用?Java JsonReader.skipValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.stream.JsonReader
的用法示例。
在下文中一共展示了JsonReader.skipValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public T read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
T instance = this.constructor.construct();
try {
in.beginObject();
while (in.hasNext()) {
BoundField field = (BoundField) this.boundFields.get(in.nextName());
if (field == null || !field.deserialized) {
in.skipValue();
} else {
field.read(in, instance);
}
}
in.endObject();
return instance;
} catch (Throwable e) {
throw new JsonSyntaxException(e);
} catch (IllegalAccessException e2) {
throw new AssertionError(e2);
}
}
示例2: addToCustomizedValueMap
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
protected void addToCustomizedValueMap(final String jsonName, final JsonReader in, final Map<String, Object> customizedValueMap) throws IOException {
switch (jsonName) {
case CloudConfigurationConstants.CPU_COUNT:
case CloudConfigurationConstants.MEMORY_MB:
customizedValueMap.put(jsonName, in.nextDouble());
break;
case CloudConfigurationConstants.APP_NAME:
case CloudConfigurationConstants.APPLICATION_CONTEXT:
case CloudConfigurationConstants.BEAN_NAME:
case CloudConfigurationConstants.JOB_EXECUTION_TYPE:
customizedValueMap.put(jsonName, in.nextString());
break;
default:
in.skipValue();
break;
}
}
示例3: setLogInfo
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public void setLogInfo(JsonReader reader) throws IOException {
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals("screen_size")) {
reader.beginObject();
while(reader.hasNext()) {
String name2 = reader.nextName();
if (name2.equals("width")) {
width = reader.nextInt();
} else if (name2.equals("height")) {
height = reader.nextInt();
} else {
reader.skipValue();
}
}
reader.endObject();
} else {
reader.skipValue();
}
}
reader.endObject();
}
示例4: processDataBody
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
/**
* Processes a conference data body and calls the appropriate data type handlers
* to process each of the objects represented therein.
*
* @param dataBody The body of data to process
* @throws IOException If there is an error parsing the data.
*/
private void processDataBody(String dataBody) throws IOException {
JsonReader reader = new JsonReader(new StringReader(dataBody));
JsonParser parser = new JsonParser();
try {
reader.setLenient(true); // To err is human
// the whole file is a single JSON object
reader.beginObject();
while (reader.hasNext()) {
// the key is "rooms", "speakers", "tracks", etc.
String key = reader.nextName();
if (mHandlerForKey.containsKey(key)) {
// pass the value to the corresponding handler
mHandlerForKey.get(key).process(parser.parse(reader));
} else {
LOGW(TAG, "Skipping unknown key in conference data json: " + key);
reader.skipValue();
}
}
reader.endObject();
} finally {
reader.close();
}
}
示例5: onWebSocketMessage
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@OnMessage
public void onWebSocketMessage(Reader message) throws IOException {
// [id, pair, price, size, side]
JsonReader reader = gson.newJsonReader(message);
reader.beginArray();
reader.skipValue();
String pair = reader.nextString();
String price = reader.nextString();
String size = reader.nextString();
reader.skipValue();
reader.endArray();
reader.close();
appendCache(pair, CoincheckTrade.builder()
.timestamp(getNow())
.price(new BigDecimal(price))
.size(new BigDecimal(size))
.build());
}
示例6: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public IStudent read(JsonReader in) throws IOException {
GsonTest.log("read");
StudentModuleImpl module = new StudentModuleImpl();
in.beginObject();
while (in.hasNext()){
switch (in.nextName()){
case "name":
module.setName(in.nextString());
break;
case "id":
module.setId(in.nextString());
break;
default:
in.skipValue();
}
}
in.endObject();
return module;
}
示例7: parseResponse
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
/**
* 太绕,还是直接用Json解析吧
*
* @param response
* @throws IOException
*/
private void parseResponse(Reader response) throws IOException {
JsonReader reader = new JsonReader(response);
reader.beginObject();
String name;
while (reader.hasNext()) {
name = reader.nextName();
if (TextUtils.equals(Field.ERROR, name)) {
reader.nextInt();
} else if (TextUtils.equals(Field.MESSAGE, name)) {
reader.nextString();
} else if (TextUtils.equals(Field.DATA, name)) {
reader.beginObject();
while (reader.hasNext()) {
reader.nextName();
reader.beginArray();
while (reader.hasNext()) {
reader.beginObject();
String itemObjKey;
while (reader.hasNext()) {
itemObjKey = reader.nextName();
if (TextUtils.equals(Field.TOKEN, itemObjKey)) {
reader.nextString();
} else {
reader.skipValue();
}
}
reader.endObject();
}
reader.endArray();
}
reader.endObject();
} else {
reader.skipValue();
}
}
reader.endObject();
reader.close();
}
示例8: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public T read(
final JsonReader in
) throws IOException {
// support null objects
if (in.peek() == JsonToken.NULL) {
// consume object
in.nextNull();
// return null
return null;
}
try {
// try to read union
return readUnion(in);
} catch (Exception e) {
// skip remaining values
while (in.hasNext()) {
in.skipValue();
}
// assert end of object
in.endObject();
// we failed in converting the union
return null;
}
}
示例9: create
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Class<?> rawType = type.getRawType();
final boolean skipSerialize = excludeClass(rawType, true);
final boolean skipDeserialize = excludeClass(rawType, false);
if (!skipSerialize && !skipDeserialize) {
return null;
}
final Gson gson2 = gson;
final TypeToken<T> typeToken = type;
return new TypeAdapter<T>() {
private TypeAdapter<T> delegate;
public T read(JsonReader in) throws IOException {
if (!skipDeserialize) {
return delegate().read(in);
}
in.skipValue();
return null;
}
public void write(JsonWriter out, T value) throws IOException {
if (skipSerialize) {
out.nullValue();
} else {
delegate().write(out, value);
}
}
private TypeAdapter<T> delegate() {
TypeAdapter<T> d = this.delegate;
if (d != null) {
return d;
}
d = GsonInternalAccess.INSTANCE.getNextAdapter(gson2, Excluder.this, typeToken);
this.delegate = d;
return d;
}
};
}
示例10: create
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(final Gson gson, final TypeToken<T> type) {
Class<?> rawType = type.getRawType();
final boolean skipSerialize = excludeClass(rawType, true);
final boolean skipDeserialize = excludeClass(rawType, false);
if (!skipSerialize && !skipDeserialize) {
return null;
}
return new TypeAdapter<T>() {
/** The delegate is lazily created because it may not be needed, and creating it may fail. */
private TypeAdapter<T> delegate;
@Override public T read(JsonReader in) throws IOException {
if (skipDeserialize) {
in.skipValue();
return null;
}
return delegate().read(in);
}
@Override public void write(JsonWriter out, T value) throws IOException {
if (skipSerialize) {
out.nullValue();
return;
}
delegate().write(out, value);
}
private TypeAdapter<T> delegate() {
TypeAdapter<T> d = delegate;
return d != null
? d
: (delegate = gson.getDelegateAdapter(Excluder.this, type));
}
};
}
示例11: readNext
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
protected String readNext(final String name, final JsonReader reader) throws IOException {
if(reader.peek() != JsonToken.NULL) {
return reader.nextString();
}
else {
reader.skipValue();
log.warn(String.format("No value for key %s", name));
return null;
}
}
示例12: getSce
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public SourceCodeEntity getSce(JsonReader reader) throws IOException {
String name = new String();
String type = new String();
String how = new String();
int length = -1;
int startLine = -1;
int endLine = -1;
int startCol = -1;
int endCol = -1;
reader.beginObject();
while(reader.hasNext()) {
String Name = reader.nextName();
if (Name.equals("name")) {
name = reader.nextString();
} else if (Name.equals("type")) {
type = reader.nextString();
} else if (Name.equals("how")) {
how = reader.nextString();
} else if (Name.equals("total_length")) {
length = reader.nextInt();
} else if (Name.equals("start_line")) {
startLine = reader.nextInt();
} else if (Name.equals("end_line")) {
endLine = reader.nextInt();
} else if (Name.equals("start_col")) {
startCol = reader.nextInt();
} else if (Name.equals("end_col")) {
endCol = reader.nextInt();
} else {
reader.skipValue();
}
}
reader.endObject();
return new SourceCodeEntity(name, type, how, length,
startLine, endLine, startCol, endCol);
}
示例13: create
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Class<?> rawType = type.getRawType();
final boolean skipSerialize = excludeClass(rawType, true);
final boolean skipDeserialize = excludeClass(rawType, false);
if (!skipSerialize && !skipDeserialize) {
return null;
}
final Gson gson2 = gson;
final TypeToken<T> typeToken = type;
return new TypeAdapter<T>() {
private TypeAdapter<T> delegate;
public T read(JsonReader in) throws IOException {
if (!skipDeserialize) {
return delegate().read(in);
}
in.skipValue();
return null;
}
public void write(JsonWriter out, T value) throws IOException {
if (skipSerialize) {
out.nullValue();
} else {
delegate().write(out, value);
}
}
private TypeAdapter<T> delegate() {
TypeAdapter<T> d = this.delegate;
if (d != null) {
return d;
}
d = gson2.getDelegateAdapter(Excluder.this, typeToken);
this.delegate = d;
return d;
}
};
}
示例14: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Car3 read(JsonReader reader) throws IOException {
Car3 car = new Car3();
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals("mark")) {
car.setMark(reader.nextString());
} else if (name.equals("model")) {
car.setModel(reader.nextInt());
} else if (name.equals("type")) {
car.setType(reader.nextString());
} else if (name.equals("maker")) {
car.setType(reader.nextString());
} else if (name.equals("cost")) {
double cost = reader.nextDouble();
double costExcludingVAT = cost / 1.21;
car.setCost(costExcludingVAT); //Remove VAT 21%
} else if (name.equals("colors") && reader.peek() != JsonToken.NULL) {
car.setColors(readStringArray(reader));
} else {
reader.skipValue();
}
}
reader.endObject();
return car;
}
示例15: readUnion
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
private T readUnion(
final JsonReader in
) throws IOException, InstantiationException, IllegalAccessException {
// assert begin of object
in.beginObject();
// create new union with default values
T union = (T) unionClass.newInstance();
// gets populated when active branch is known
UnionMemberInfo unionMemberInfo = null;
while (in.hasNext()) {
// get name of next item
String name = in.nextName();
if (DISCRIMINATOR_FIELD_NAME.equals(name)) {
// read discriminator
Object discriminatorObject = discriminatorTypeAdapter.read(in);
// if discriminator is not valid, return union with defaults
if (discriminatorObject == null) {
// skip remaining values
while (in.hasNext()) {
in.skipValue();
}
// assert end of object
in.endObject();
// return empty union with default values
return union;
}
// remember discriminator
unionMemberInfo = memberInfoMap.get(discriminatorObject.toString());
// set discriminator on union
fieldAccess.set(union, DISCRIMINATOR_FIELD_NAME, discriminatorObject);
} else if (unionMemberInfo != null
&& unionMemberInfo.fieldName.equals(name)) {
Object fieldObject = unionMemberInfo.typeAdapter.read(in);
fieldAccess.set(union, unionMemberInfo.fieldName, fieldObject);
} else {
in.skipValue();
}
}
// assert end of object
in.endObject();
// return result
return union;
}