Java Code Examples for com.google.gson.stream.JsonToken#END_OBJECT
The following examples show how to use
com.google.gson.stream.JsonToken#END_OBJECT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BsonReader.java From immutables with Apache License 2.0 | 6 votes |
@Override public JsonToken peek() throws IOException { switch (state()) { case INITIAL: case SCOPE_DOCUMENT: case TYPE: advance(); return peek(); case NAME: return JsonToken.NAME; case END_OF_DOCUMENT: return JsonToken.END_OBJECT; case END_OF_ARRAY: return JsonToken.END_ARRAY; case DONE: return JsonToken.END_DOCUMENT; case VALUE: return toGsonToken(delegate.getCurrentBsonType()); default: throw new IllegalStateException("Unexpected state: " + state() + " currentType:" + delegate.getCurrentBsonType()); } }
Example 2
Source File: Common.java From jus with Apache License 2.0 | 6 votes |
@Override public AnInterface read(JsonReader jsonReader) throws IOException { jsonReader.beginObject(); String name = null; while (jsonReader.peek() != JsonToken.END_OBJECT) { switch (jsonReader.nextName()) { case "name": name = jsonReader.nextString(); break; } } jsonReader.endObject(); return new AnImplementation(name); }
Example 3
Source File: UsersStreamDeserializer.java From java-json-benchmark with MIT License | 6 votes |
@Override public Users gson(JsonReader reader) throws IOException { Users uc = new Users(); reader.beginObject(); JsonToken token; while ((token = reader.peek()) != JsonToken.END_OBJECT) { if (token == JsonToken.NAME) { String fieldname = reader.nextName(); if ("users".equals(fieldname)) { uc.users = new ArrayList<>(); reader.beginArray(); while (reader.peek() != JsonToken.END_ARRAY) { uc.users.add(gsonUser(reader)); } reader.endArray(); } } } reader.endObject(); return uc; }
Example 4
Source File: SystemSettingsJsonAdapter.java From esjc with MIT License | 6 votes |
@Override public SystemSettings read(JsonReader reader) throws IOException { if (reader.peek() == JsonToken.NULL) { return null; } SystemSettings.Builder builder = SystemSettings.newBuilder(); reader.beginObject(); while (reader.peek() != JsonToken.END_OBJECT && reader.hasNext()) { String name = reader.nextName(); switch (name) { case USER_STREAM_ACL: builder.userStreamAcl(streamAclJsonAdapter.read(reader)); break; case SYSTEM_STREAM_ACL: builder.systemStreamAcl(streamAclJsonAdapter.read(reader)); break; } } reader.endObject(); return builder.build(); }
Example 5
Source File: JsonMapper.java From firebase-admin-java with Apache License 2.0 | 5 votes |
private static Map<String, Object> unwrapJsonObject(JsonReader jsonReader) throws IOException { Map<String, Object> map = new HashMap<>(); jsonReader.beginObject(); while (jsonReader.peek() != JsonToken.END_OBJECT) { String key = jsonReader.nextName(); map.put(key, unwrapJson(jsonReader)); } jsonReader.endObject(); return map; }
Example 6
Source File: TypeAdapters.java From framework with GNU Affero General Public License v3.0 | 5 votes |
@Override public Calendar read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull(); return null; } in.beginObject(); int year = 0; int month = 0; int dayOfMonth = 0; int hourOfDay = 0; int minute = 0; int second = 0; while (in.peek() != JsonToken.END_OBJECT) { String name = in.nextName(); int value = in.nextInt(); if (YEAR.equals(name)) { year = value; } else if (MONTH.equals(name)) { month = value; } else if (DAY_OF_MONTH.equals(name)) { dayOfMonth = value; } else if (HOUR_OF_DAY.equals(name)) { hourOfDay = value; } else if (MINUTE.equals(name)) { minute = value; } else if (SECOND.equals(name)) { second = value; } } in.endObject(); return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second); }
Example 7
Source File: TypeAdapters.java From gson with Apache License 2.0 | 5 votes |
@Override public Calendar read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull(); return null; } in.beginObject(); int year = 0; int month = 0; int dayOfMonth = 0; int hourOfDay = 0; int minute = 0; int second = 0; while (in.peek() != JsonToken.END_OBJECT) { String name = in.nextName(); int value = in.nextInt(); if (YEAR.equals(name)) { year = value; } else if (MONTH.equals(name)) { month = value; } else if (DAY_OF_MONTH.equals(name)) { dayOfMonth = value; } else if (HOUR_OF_DAY.equals(name)) { hourOfDay = value; } else if (MINUTE.equals(name)) { minute = value; } else if (SECOND.equals(name)) { second = value; } } in.endObject(); return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second); }
Example 8
Source File: StreamAclJsonAdapter.java From esjc with MIT License | 5 votes |
@Override public StreamAcl read(JsonReader reader) throws IOException { StreamAcl.Builder builder = StreamAcl.newBuilder(); reader.beginObject(); while (reader.peek() != JsonToken.END_OBJECT && reader.hasNext()) { String name = reader.nextName(); switch (name) { case ACL_READ: builder.readRoles(readRoles(reader)); break; case ACL_WRITE: builder.writeRoles(readRoles(reader)); break; case ACL_DELETE: builder.deleteRoles(readRoles(reader)); break; case ACL_META_READ: builder.metaReadRoles(readRoles(reader)); break; case ACL_META_WRITE: builder.metaWriteRoles(readRoles(reader)); break; } } reader.endObject(); return builder.build(); }
Example 9
Source File: TypeAdapters.java From letv with Apache License 2.0 | 5 votes |
public Calendar read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull(); return null; } in.beginObject(); int year = 0; int month = 0; int dayOfMonth = 0; int hourOfDay = 0; int minute = 0; int second = 0; while (in.peek() != JsonToken.END_OBJECT) { String name = in.nextName(); int value = in.nextInt(); if (YEAR.equals(name)) { year = value; } else if (MONTH.equals(name)) { month = value; } else if (DAY_OF_MONTH.equals(name)) { dayOfMonth = value; } else if (HOUR_OF_DAY.equals(name)) { hourOfDay = value; } else if (MINUTE.equals(name)) { minute = value; } else if (SECOND.equals(name)) { second = value; } } in.endObject(); return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second); }
Example 10
Source File: JsonParserReader.java From immutables with Apache License 2.0 | 5 votes |
private static JsonToken toGsonToken(com.fasterxml.jackson.core.JsonToken token) { switch (token) { case START_ARRAY: return JsonToken.BEGIN_ARRAY; case END_ARRAY: return JsonToken.END_ARRAY; case START_OBJECT: return JsonToken.BEGIN_OBJECT; case END_OBJECT: return JsonToken.END_OBJECT; case FIELD_NAME: return JsonToken.NAME; case VALUE_FALSE: return JsonToken.BOOLEAN; case VALUE_TRUE: return JsonToken.BOOLEAN; case VALUE_NULL: return JsonToken.NULL; case VALUE_NUMBER_INT: return JsonToken.NUMBER; case VALUE_NUMBER_FLOAT: return JsonToken.NUMBER; case VALUE_STRING: case VALUE_EMBEDDED_OBJECT: return JsonToken.STRING; default: // Not semantically equivalent return JsonToken.NULL; } }
Example 11
Source File: StreamMetadataJsonAdapter.java From esjc with MIT License | 4 votes |
@Override public StreamMetadata read(JsonReader reader) throws IOException { StreamMetadata.Builder builder = StreamMetadata.newBuilder(); if (reader.peek() == JsonToken.NULL) { return null; } reader.beginObject(); while (reader.peek() != JsonToken.END_OBJECT && reader.hasNext()) { String name = reader.nextName(); switch (name) { case MAX_COUNT: builder.maxCount(reader.nextLong()); break; case MAX_AGE: builder.maxAge(Duration.ofSeconds(reader.nextLong())); break; case TRUNCATE_BEFORE: builder.truncateBefore(reader.nextLong()); break; case CACHE_CONTROL: builder.cacheControl(Duration.ofSeconds(reader.nextLong())); break; case ACL: StreamAcl acl = streamAclJsonAdapter.read(reader); if (acl != null) { builder.aclReadRoles(acl.readRoles); builder.aclWriteRoles(acl.writeRoles); builder.aclDeleteRoles(acl.deleteRoles); builder.aclMetaReadRoles(acl.metaReadRoles); builder.aclMetaWriteRoles(acl.metaWriteRoles); } break; default: switch (reader.peek()) { case NULL: reader.nextNull(); builder.customProperty(name, (String) null); break; case BEGIN_ARRAY: List<Object> values = new ArrayList<>(); reader.beginArray(); while (reader.peek() != JsonToken.END_ARRAY) { switch (reader.peek()) { case NULL: reader.nextNull(); values.add(null); break; case BOOLEAN: values.add(reader.nextBoolean()); break; case NUMBER: values.add(new BigDecimal(reader.nextString())); break; case STRING: values.add(reader.nextString()); } } reader.endArray(); if (values.stream().anyMatch(v -> v instanceof Boolean)) { builder.customProperty(name, values.stream().toArray(Boolean[]::new)); } else if (values.stream().anyMatch(v -> v instanceof Number)) { builder.customProperty(name, values.stream().toArray(Number[]::new)); } else { builder.customProperty(name, values.stream().toArray(String[]::new)); } break; case BOOLEAN: builder.customProperty(name, reader.nextBoolean()); break; case NUMBER: builder.customProperty(name, new BigDecimal(reader.nextString())); break; case STRING: builder.customProperty(name, reader.nextString()); break; default: reader.skipValue(); } } } reader.endObject(); return builder.build(); }
Example 12
Source File: SpliceDoNotRetryIOExceptionWrapping.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
@Override public StandardException read(JsonReader in) throws IOException { in.beginObject(); int severity = 0; String textMessage = null; String sqlState = null; String messageId = null; List<String> objectStrings = null; while (in.peek() != JsonToken.END_OBJECT) { String nextName = in.nextName(); if ("severity".equals(nextName)) severity = in.nextInt(); else if ("textMessage".equals(nextName)) textMessage = in.nextString(); else if ("sqlState".equals(nextName)) sqlState = in.nextString(); else if ("messageId".equals(nextName)) messageId = in.nextString(); else if ("arguments".equals(nextName)) { if (in.peek() != JsonToken.NULL) { in.beginArray(); objectStrings = new ArrayList<String>(); while (in.peek() != JsonToken.END_ARRAY) { objectStrings.add(in.nextString()); } in.endArray(); } else in.nextNull(); } } in.endObject(); StandardException se; if (objectStrings != null) { Object[] objects = new Object[objectStrings.size()]; objectStrings.toArray(objects); se = StandardException.newException(messageId, objects); } else { se = StandardException.newException(messageId); } se.setSeverity(severity); se.setSqlState(sqlState); se.setTextMessage(textMessage); return se; }
Example 13
Source File: JsonTreeReader.java From MiBandDecompiled with Apache License 2.0 | 4 votes |
public boolean hasNext() { JsonToken jsontoken = peek(); return jsontoken != JsonToken.END_OBJECT && jsontoken != JsonToken.END_ARRAY; }
Example 14
Source File: JsonTreeReader.java From MiBandDecompiled with Apache License 2.0 | 4 votes |
public JsonToken peek() { if (c.isEmpty()) { return JsonToken.END_DOCUMENT; } Object obj = a(); if (obj instanceof Iterator) { boolean flag = c.get(-2 + c.size()) instanceof JsonObject; Iterator iterator = (Iterator)obj; if (iterator.hasNext()) { if (flag) { return JsonToken.NAME; } else { c.add(iterator.next()); return peek(); } } if (flag) { return JsonToken.END_OBJECT; } else { return JsonToken.END_ARRAY; } } if (obj instanceof JsonObject) { return JsonToken.BEGIN_OBJECT; } if (obj instanceof JsonArray) { return JsonToken.BEGIN_ARRAY; } if (obj instanceof JsonPrimitive) { JsonPrimitive jsonprimitive = (JsonPrimitive)obj; if (jsonprimitive.isString()) { return JsonToken.STRING; } if (jsonprimitive.isBoolean()) { return JsonToken.BOOLEAN; } if (jsonprimitive.isNumber()) { return JsonToken.NUMBER; } else { throw new AssertionError(); } } if (obj instanceof JsonNull) { return JsonToken.NULL; } if (obj == b) { throw new IllegalStateException("JsonReader is closed"); } else { throw new AssertionError(); } }
Example 15
Source File: D.java From MiBandDecompiled with Apache License 2.0 | 4 votes |
public Calendar a(JsonReader jsonreader) { int i = 0; if (jsonreader.peek() == JsonToken.NULL) { jsonreader.nextNull(); return null; } jsonreader.beginObject(); int j = 0; int k = 0; int l = 0; int i1 = 0; int j1 = 0; do { if (jsonreader.peek() == JsonToken.END_OBJECT) { break; } String s = jsonreader.nextName(); int k1 = jsonreader.nextInt(); if ("year".equals(s)) { j1 = k1; } else if ("month".equals(s)) { i1 = k1; } else if ("dayOfMonth".equals(s)) { l = k1; } else if ("hourOfDay".equals(s)) { k = k1; } else if ("minute".equals(s)) { j = k1; } else if ("second".equals(s)) { i = k1; } } while (true); jsonreader.endObject(); return new GregorianCalendar(j1, i1, l, k, j, i); }
Example 16
Source File: JsonTreeReader.java From gson with Apache License 2.0 | 4 votes |
@Override public boolean hasNext() throws IOException { JsonToken token = peek(); return token != JsonToken.END_OBJECT && token != JsonToken.END_ARRAY; }
Example 17
Source File: JsonTreeReader.java From gson with Apache License 2.0 | 4 votes |
@Override public JsonToken peek() throws IOException { if (stackSize == 0) { return JsonToken.END_DOCUMENT; } Object o = peekStack(); if (o instanceof Iterator) { boolean isObject = stack[stackSize - 2] instanceof JsonObject; Iterator<?> iterator = (Iterator<?>) o; if (iterator.hasNext()) { if (isObject) { return JsonToken.NAME; } else { push(iterator.next()); return peek(); } } else { return isObject ? JsonToken.END_OBJECT : JsonToken.END_ARRAY; } } else if (o instanceof JsonObject) { return JsonToken.BEGIN_OBJECT; } else if (o instanceof JsonArray) { return JsonToken.BEGIN_ARRAY; } else if (o instanceof JsonPrimitive) { JsonPrimitive primitive = (JsonPrimitive) o; if (primitive.isString()) { return JsonToken.STRING; } else if (primitive.isBoolean()) { return JsonToken.BOOLEAN; } else if (primitive.isNumber()) { return JsonToken.NUMBER; } else { throw new AssertionError(); } } else if (o instanceof JsonNull) { return JsonToken.NULL; } else if (o == SENTINEL_CLOSED) { throw new IllegalStateException("JsonReader is closed"); } else { throw new AssertionError(); } }
Example 18
Source File: JsonTreeReader.java From letv with Apache License 2.0 | 4 votes |
public JsonToken peek() throws IOException { if (this.stack.isEmpty()) { return JsonToken.END_DOCUMENT; } Iterator<?> o = peekStack(); if (o instanceof Iterator) { boolean isObject = this.stack.get(this.stack.size() - 2) instanceof JsonObject; Iterator<?> iterator = o; if (!iterator.hasNext()) { return isObject ? JsonToken.END_OBJECT : JsonToken.END_ARRAY; } else { if (isObject) { return JsonToken.NAME; } this.stack.add(iterator.next()); return peek(); } } else if (o instanceof JsonObject) { return JsonToken.BEGIN_OBJECT; } else { if (o instanceof JsonArray) { return JsonToken.BEGIN_ARRAY; } if (o instanceof JsonPrimitive) { JsonPrimitive primitive = (JsonPrimitive) o; if (primitive.isString()) { return JsonToken.STRING; } if (primitive.isBoolean()) { return JsonToken.BOOLEAN; } if (primitive.isNumber()) { return JsonToken.NUMBER; } throw new AssertionError(); } else if (o instanceof JsonNull) { return JsonToken.NULL; } else { if (o == SENTINEL_CLOSED) { throw new IllegalStateException("JsonReader is closed"); } throw new AssertionError(); } } }
Example 19
Source File: JsonTreeReader.java From framework with GNU Affero General Public License v3.0 | 4 votes |
@Override public boolean hasNext() throws IOException { JsonToken token = peek(); return token != JsonToken.END_OBJECT && token != JsonToken.END_ARRAY; }
Example 20
Source File: JsonTreeReader.java From letv with Apache License 2.0 | 4 votes |
public boolean hasNext() throws IOException { JsonToken token = peek(); return (token == JsonToken.END_OBJECT || token == JsonToken.END_ARRAY) ? false : true; }