本文整理汇总了Java中com.google.gson.stream.JsonReader.nextBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java JsonReader.nextBoolean方法的具体用法?Java JsonReader.nextBoolean怎么用?Java JsonReader.nextBoolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.stream.JsonReader
的用法示例。
在下文中一共展示了JsonReader.nextBoolean方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Boolean read(JsonReader in) throws IOException {
JsonToken peek = in.peek();
switch (peek) {
case BOOLEAN:
return in.nextBoolean();
case NULL:
in.nextNull();
return null;
case NUMBER:
return in.nextInt() != 0;
case STRING:
return in.nextString().equalsIgnoreCase("1");
default:
throw new IllegalStateException("Expected BOOLEAN or NUMBER but was " + peek);
}
}
示例2: readPrimitiveOrItsBox
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public static Object readPrimitiveOrItsBox(JsonReader reader, Property p) throws IOException {
Class<?> type = p.getType();
if (type == void.class || type == Void.class) {
return null;
} else if (type == boolean.class || type == Boolean.class) {
return reader.nextBoolean();
} else if (type == byte.class || type == Byte.class) {
return (byte)reader.nextInt();
} else if (type == short.class || type == Short.class) {
return (short)reader.nextInt();
} else if (type == int.class || type == Integer.class) {
return reader.nextInt();
} else if (type == long.class || type == Long.class) {
return reader.nextLong();
} else if (type == char.class || type == Character.class) {
return (char)reader.nextLong();
} else if (type == float.class || type == Float.class) {
return (float)reader.nextDouble();
} else if (type == double.class || type == Double.class) {
return reader.nextDouble();
} else {
throw new IllegalStateException();
}
}
示例3: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override public Object read(JsonReader in) throws IOException {
JsonToken token = in.peek();
switch (token) {
case BEGIN_ARRAY:
List<Object> list = new ArrayList<Object>();
in.beginArray();
while (in.hasNext()) {
list.add(read(in));
}
in.endArray();
return list;
case BEGIN_OBJECT:
Map<String, Object> map = new LinkedTreeMap<String, Object>();
in.beginObject();
while (in.hasNext()) {
map.put(in.nextName(), read(in));
}
in.endObject();
return map;
case STRING:
return in.nextString();
case NUMBER:
return in.nextDouble();
case BOOLEAN:
return in.nextBoolean();
case NULL:
in.nextNull();
return null;
default:
throw new IllegalStateException();
}
}
示例4: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public BitSet read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
BitSet bitset = new BitSet();
in.beginArray();
int i = 0;
JsonToken tokenType = in.peek();
while (tokenType != JsonToken.END_ARRAY) {
boolean set;
switch (tokenType) {
case NUMBER:
set = in.nextInt() != 0;
break;
case BOOLEAN:
set = in.nextBoolean();
break;
case STRING:
String stringValue = in.nextString();
try {
set = Integer.parseInt(stringValue) != 0;
} catch (NumberFormatException e) {
throw new JsonSyntaxException(
"Error: Expecting: bitset number value (1, 0), Found: " + stringValue);
}
break;
default:
throw new JsonSyntaxException("Invalid bitset value type: " + tokenType);
}
if (set) {
bitset.set(i);
}
++i;
tokenType = in.peek();
}
in.endArray();
return bitset;
}
示例5: gson
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Benchmark
public void gson(Blackhole bh) throws Exception {
JsonReader reader = new JsonReader(new CharArrayReader(chars));
while (true) {
JsonToken token = reader.peek();
switch (token) {
case BEGIN_ARRAY:
reader.beginArray();
break;
case END_ARRAY:
reader.endArray();
break;
case BEGIN_OBJECT:
reader.beginObject();
break;
case END_OBJECT:
reader.endObject();
break;
case NAME:
reader.nextName();
break;
case STRING:
reader.nextString();
break;
case NUMBER:
reader.nextString();
break;
case BOOLEAN:
reader.nextBoolean();
break;
case NULL:
reader.nextNull();
break;
case END_DOCUMENT:
reader.close();
return;
}
}
}
示例6: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Object read(JsonReader in) throws IOException {
JsonToken token = in.peek();
switch (token) {
case BEGIN_ARRAY:
List<Object> list = new ArrayList<>();
in.beginArray();
while (in.hasNext()) {
list.add(read(in));
}
in.endArray();
return list;
case BEGIN_OBJECT:
Map<String, Object> map = new LinkedTreeMap<>();
in.beginObject();
while (in.hasNext()) {
map.put(in.nextName(), read(in));
}
in.endObject();
return map;
case STRING:
return in.nextString();
case NUMBER:
return getNumber(in.nextString());
case BOOLEAN:
return in.nextBoolean();
case NULL:
in.nextNull();
return null;
default:
throw new IllegalStateException();
}
}
示例7: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public CloudAppConfiguration read(final JsonReader in) throws IOException {
String appURL = "";
String appName = "";
String bootstrapScript = "";
double cpuCount = 1.0d;
double memoryMB = 128.0d;
boolean appCacheEnable = true;
int eventTraceSamplingCount = 0;
in.beginObject();
while (in.hasNext()) {
String jsonName = in.nextName();
switch (jsonName) {
case APP_NAME:
appName = in.nextString();
break;
case APP_URL:
appURL = in.nextString();
break;
case BOOTSTRAP_SCRIPT:
bootstrapScript = in.nextString();
break;
case CPU_COUNT:
cpuCount = in.nextDouble();
break;
case MEMORY_MB:
memoryMB = in.nextDouble();
break;
case APP_CACHE_ENABLE:
appCacheEnable = in.nextBoolean();
break;
case EVENT_TRACE_SAMPLING_COUNT:
eventTraceSamplingCount = in.nextInt();
break;
default:
break;
}
}
in.endObject();
return new CloudAppConfiguration(appName, appURL, bootstrapScript, cpuCount, memoryMB, appCacheEnable, eventTraceSamplingCount);
}
示例8: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public T read(final JsonReader in) throws IOException {
String jobName = "";
String cron = "";
int shardingTotalCount = 0;
String shardingItemParameters = "";
String jobParameter = "";
boolean failover = false;
boolean misfire = failover;
String description = "";
JobProperties jobProperties = new JobProperties();
JobType jobType = null;
String jobClass = "";
boolean streamingProcess = false;
String scriptCommandLine = "";
Map<String, Object> customizedValueMap = new HashMap<>(32, 1);
in.beginObject();
while (in.hasNext()) {
String jsonName = in.nextName();
switch (jsonName) {
case "jobName":
jobName = in.nextString();
break;
case "cron":
cron = in.nextString();
break;
case "shardingTotalCount":
shardingTotalCount = in.nextInt();
break;
case "shardingItemParameters":
shardingItemParameters = in.nextString();
break;
case "jobParameter":
jobParameter = in.nextString();
break;
case "failover":
failover = in.nextBoolean();
break;
case "misfire":
misfire = in.nextBoolean();
break;
case "description":
description = in.nextString();
break;
case "jobProperties":
jobProperties = getJobProperties(in);
break;
case "jobType":
jobType = JobType.valueOf(in.nextString());
break;
case "jobClass":
jobClass = in.nextString();
break;
case "streamingProcess":
streamingProcess = in.nextBoolean();
break;
case "scriptCommandLine":
scriptCommandLine = in.nextString();
break;
default:
addToCustomizedValueMap(jsonName, in, customizedValueMap);
break;
}
}
in.endObject();
JobCoreConfiguration coreConfig = getJobCoreConfiguration(jobName, cron, shardingTotalCount, shardingItemParameters,
jobParameter, failover, misfire, description, jobProperties);
JobTypeConfiguration typeConfig = getJobTypeConfiguration(coreConfig, jobType, jobClass, streamingProcess, scriptCommandLine);
return getJobRootConfiguration(typeConfig, customizedValueMap);
}
示例9: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public BitSet read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
BitSet bitset = new BitSet();
in.beginArray();
int i = 0;
JsonToken tokenType = in.peek();
while (tokenType != JsonToken.END_ARRAY) {
boolean set;
switch (tokenType) {
case NUMBER:
if (in.nextInt() == 0) {
set = false;
break;
}
set = true;
break;
case BOOLEAN:
set = in.nextBoolean();
break;
case STRING:
String stringValue = in.nextString();
try {
set = Integer.parseInt(stringValue) != 0;
break;
} catch (NumberFormatException e) {
throw new JsonSyntaxException("Error: Expecting: bitset number value (1, 0), Found: " + stringValue);
}
default:
throw new JsonSyntaxException("Invalid bitset value type: " + tokenType);
}
if (set) {
bitset.set(i);
}
i++;
tokenType = in.peek();
}
in.endArray();
return bitset;
}
示例10: parse
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException {
try {
final JsonReader reader = new JsonReader(new InputStreamReader(file.getInputStream(), "UTF-8"));
reader.beginArray();
String url;
String user;
boolean ssl;
Protocol protocol;
while(reader.hasNext()) {
reader.beginObject();
boolean skip = false;
url = null;
ssl = false;
protocol = null;
user = null;
while(reader.hasNext()) {
final String name = reader.nextName();
switch(name) {
case "url":
url = this.readNext(name, reader);
if(StringUtils.isBlank(url)) {
skip = true;
}
break;
case "ssl":
ssl = reader.nextBoolean();
break;
case "user":
user = this.readNext(name, reader);
break;
case "type":
final String type = this.readNext(name, reader);
switch(type) {
case "google_cloud_storage":
protocol = protocols.forType(Protocol.Type.googlestorage);
break;
case "gdrive":
protocol = protocols.forType(Protocol.Type.googledrive);
break;
default:
protocol = protocols.forName(type);
}
break;
default:
log.warn(String.format("Ignore property %s", name));
reader.skipValue();
break;
}
}
reader.endObject();
if(!skip && protocol != null && StringUtils.isNotBlank(user)) {
if(ssl) {
switch(protocol.getType()) {
case ftp:
protocol = protocols.forScheme(Scheme.ftps);
break;
case dav:
protocol = protocols.forScheme(Scheme.davs);
break;
}
}
this.add(HostParser.parse(protocols, protocol, url));
}
}
reader.endArray();
}
catch(IllegalStateException | IOException e) {
throw new LocalAccessDeniedException(e.getMessage(), e);
}
}
示例11: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Message read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
in.beginObject();
String messageType = null, id = null, seq = null, request_seq = null, method = null, message = null;
boolean success = true;
Object rawParams = null;
Object body = null;
while (in.hasNext()) {
String name = in.nextName();
switch (name) {
case "seq": {
seq = in.nextString();
break;
}
case "request_seq": {
// on responses we treat the request_seq as the id
request_seq = in.nextString();
break;
}
case "type": {
messageType = in.nextString();
break;
}
case "success": {
success = in.nextBoolean();
break;
}
case "command": {
method = in.nextString();
break;
}
case "event": {
method = in.nextString();
break;
}
case "message": {
message = in.nextString();
break;
}
case "arguments": {
rawParams = parseParams(in, method);
break;
}
case "body": {
if ("event".equals(messageType)) {
body = parseParams(in, method);
} else if ("response".equals(messageType)) {
body = parseResult(in, request_seq);
}
break;
}
default:
in.skipValue();
}
}
id = request_seq != null ? request_seq : seq;
in.endObject();
Object params = parseParams(rawParams, method);
return createMessage(messageType, id, method, success, message, params, body);
}
示例12: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public BitSet read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
BitSet bitset = new BitSet();
in.beginArray();
int i = 0;
JsonToken tokenType = in.peek();
while (tokenType != JsonToken.END_ARRAY) {
boolean set;
switch (tokenType) {
case NUMBER:
if (in.nextInt() == 0) {
set = false;
break;
}
set = true;
break;
case BOOLEAN:
set = in.nextBoolean();
break;
case STRING:
String stringValue = in.nextString();
try {
set = Integer.parseInt(stringValue) != 0;
break;
} catch (NumberFormatException e) {
throw new JsonSyntaxException("Error: Expecting: bitset number value " +
"(1, 0), Found: " + stringValue);
}
default:
throw new JsonSyntaxException("Invalid bitset value type: " + tokenType);
}
if (set) {
bitset.set(i);
}
i++;
tokenType = in.peek();
}
in.endArray();
return bitset;
}
示例13: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public T read(JsonReader in) throws IOException {
Object res;
in.beginObject();
LOG.info(in.nextName());
String clazzName = in.nextString();
LOG.info(clazzName);
LOG.info(in.nextName());
try {
Class<?> typeOfT = Class.forName(clazzName);
// TypeAdapter<?> del = gson.getDelegateAdapter(new ObjectTypeAdapterFactory(),
// );
TypeAdapter<?> del = gson.getAdapter(TypeToken.get(typeOfT));
LOG.info("ta: " + del + " taDel: " + delegate + " tt: " + TypeToken.get(typeOfT));
if (typeOfT.isArray()) {
del = com.google.gson.internal.bind.ArrayTypeAdapter.FACTORY.create(gson, TypeToken.get(typeOfT));
} else {
del = delegate;
}
JsonToken peek = in.peek();
switch (peek) {
case STRING:
res = in.nextString();
break;
case BOOLEAN:
res = in.nextBoolean();
break;
case NUMBER:
if (Long.class.equals(typeOfT)) {
res = in.nextLong();
} else if (Integer.class.equals(typeOfT)) {
res = in.nextInt();
} else {
res = in.nextDouble();
}
break;
default:
res = (T) del.read(in);
}
} catch (ClassNotFoundException e) {
throw new JsonParseException(e);
}
// res = delegate.read(in);
in.endObject();
return (T) res;
}