List of usage examples for com.google.gson.stream JsonReader nextString
public String nextString() throws IOException
From source file:net.minecraftforge.gradle.util.json.forgeversion.ForgeArtifactAdapter.java
License:Open Source License
@Override public ForgeArtifact read(JsonReader in) throws IOException { ForgeArtifact out = new ForgeArtifact(); in.beginArray();/*w ww .j av a2s . c o m*/ out.ext = in.nextString(); out.classifier = in.nextString(); out.hash = in.nextString(); in.endArray(); return out; }
From source file:net.minecrell.workbench.tools.util.gson.LowerCaseEnumTypeAdapterFactory.java
License:Open Source License
@Override public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { @SuppressWarnings("unchecked") Class<T> rawType = (Class<T>) type.getRawType(); if (!rawType.isEnum()) { return null; }/*ww w.jav a2 s. co m*/ final Map<String, T> lookup = new HashMap<>(); for (T constant : rawType.getEnumConstants()) { lookup.put(toLowerCase(constant), constant); } return new TypeAdapter<T>() { @Override public void write(JsonWriter out, T value) throws IOException { if (value == null) { out.nullValue(); } else { out.value(toLowerCase(value)); } } @Override public T read(JsonReader reader) throws IOException { if (reader.peek() == JsonToken.NULL) { reader.nextNull(); return null; } else { return lookup.get(reader.nextString()); } } }; }
From source file:net.oneandone.stool.configuration.adapter.ExpireTypeAdapter.java
License:Apache License
@Override public Expire read(JsonReader in) throws IOException { return Expire.fromString(in.nextString()); }
From source file:net.oneandone.stool.configuration.adapter.FileNodeTypeAdapter.java
License:Apache License
@Override public FileNode read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull();//from w ww . j a v a2 s . c o m return null; } return world.file(in.nextString()); }
From source file:net.oneandone.stool.configuration.adapter.UntilTypeAdapter.java
License:Apache License
@Override public Until read(JsonReader in) throws IOException { return Until.fromString(in.nextString()); }
From source file:net.oneandone.stool.configuration.adapter.VersionTypeAdapter.java
License:Apache License
@Override public Version read(JsonReader in) throws IOException { return Version.valueOf(in.nextString()); }
From source file:net.technicpack.launchercore.util.LowerCaseEnumTypeAdapterFactory.java
License:Open Source License
@SuppressWarnings("unchecked") public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { Class rawType = type.getRawType(); if (!rawType.isEnum()) { return null; }/*w ww . java 2 s.c om*/ final Map<String, T> lowercaseToConstant = new HashMap<String, T>(); for (Object constant : rawType.getEnumConstants()) { lowercaseToConstant.put(toLowercase(constant), (T) constant); } return new TypeAdapter<T>() { public void write(JsonWriter out, T value) throws IOException { if (value == null) out.nullValue(); else out.value(LowerCaseEnumTypeAdapterFactory.this.toLowercase(value)); } public T read(JsonReader reader) throws IOException { if (reader.peek() == JsonToken.NULL) { reader.nextNull(); return null; } return lowercaseToConstant.get(reader.nextString()); } }; }
From source file:net.visualillusionsent.newu.NewUStation.java
License:Open Source License
NewUStation(String stationName, JsonReader reader) throws IOException { String tempName = stationName == null ? UUID.randomUUID().toString() : stationName; this.discoverers = Collections.synchronizedList(new ArrayList<String>()); this.station = new Location(0, 0, 0); // Initialize while (reader.hasNext()) { String object = reader.nextName(); if (object.equals("Name")) { tempName = reader.nextString(); }//w ww . j ava 2s .com if (object.equals("World")) { station.setWorldName(reader.nextString()); } else if (object.equals("Dimension")) { station.setType(DimensionType.fromName(reader.nextString())); } else if (object.equals("X")) { station.setX(reader.nextDouble()); } else if (object.equals("Y")) { station.setY(reader.nextDouble()); } else if (object.equals("Z")) { station.setZ(reader.nextDouble()); } else if (object.equals("RotX")) { station.setRotation((float) reader.nextDouble()); } else if (object.equals("RotY")) { station.setPitch((float) reader.nextDouble()); } else { reader.skipValue(); // Unknown } } this.name = tempName; }
From source file:net.visualillusionsent.newu.StationTracker.java
License:Open Source License
private void loadStations() { try {//from w w w . j a v a 2s .c o m File stationsJSON = new File(NewU.cfgDir, "stations.json"); if (!stationsJSON.exists()) { stationsJSON.createNewFile(); return; } JsonReader reader = new JsonReader(new FileReader(stationsJSON)); reader.beginObject(); // Begin main object while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("Station")) { NewUStation temp = null; reader.beginObject(); // Begin Station String foundName = null; while (reader.hasNext()) { name = reader.nextName(); if (name.equals("Name")) { foundName = reader.nextString(); continue; } else if (name.equals("Location")) { reader.beginObject(); // Begin Location temp = new NewUStation(foundName, reader); // Pass reader into NewUStation object for parsing reader.endObject(); // End Location } else if (name.equals("Discoverers")) { reader.beginArray(); // Begin Discoverers while (reader.hasNext()) { if (temp != null) { temp.addDiscoverer(reader.nextString()); } } reader.endArray(); // End Discoverers } else { reader.skipValue(); // UNKNOWN THING } } if (temp != null) { stations.put(temp.getName(), temp); } reader.endObject(); //End Station } } reader.endObject(); // End main object reader.close(); } catch (IOException e) { logger.log(Level.SEVERE, "Failed to load stations..."); } }
From source file:ninja.leaping.configurate.gson.GsonConfigurationLoader.java
License:Apache License
private void parseValue(JsonReader parser, ConfigurationNode node) throws IOException { JsonToken token = parser.peek();/*www . j a va 2 s . co m*/ switch (token) { case BEGIN_OBJECT: parseObject(parser, node); break; case BEGIN_ARRAY: parseArray(parser, node); break; case NUMBER: double nextDouble = parser.nextDouble(); int nextInt = (int) nextDouble; long nextLong = (long) nextDouble; if (nextInt == nextDouble) { node.setValue(nextInt); // They don't do much for us here in Gsonland } else if (nextLong == nextDouble) { node.setValue(nextLong); } else { node.setValue(nextDouble); } break; case STRING: node.setValue(parser.nextString()); break; case BOOLEAN: node.setValue(parser.nextBoolean()); break; case NULL: // Ignored values case NAME: break; default: throw new IOException("Unsupported token type: " + token); } }