use of com.google.gson.GsonBuilder in project MyDiary by erttyy8821.
the class ExportAsyncTask method outputBackupJson.
private void outputBackupJson() throws IOException {
Writer writer = new FileWriter(backupJsonFilePath);
Gson gson = new GsonBuilder().create();
gson.toJson(backupManager, writer);
writer.close();
}
use of com.google.gson.GsonBuilder in project immutables by immutables.
the class JaxrsTest method propagateGsonAttributes.
@Test
public void propagateGsonAttributes() {
Gson gson = new GsonBuilder().serializeNulls().disableHtmlEscaping().setPrettyPrinting().create();
GsonOptions options = new GsonOptions(gson, true);
JsonReader reader = new JsonReader(new StringReader(""));
options.setReaderOptions(reader);
check(reader.isLenient());
JsonWriter writer = new JsonWriter(new StringWriter());
options.setWriterOptions(writer);
check(writer.isLenient());
check(!writer.isHtmlSafe());
check(writer.getSerializeNulls());
// checks pretty printing
check(gson.toJson(Collections.singletonMap("k", "v"))).is("{\n \"k\": \"v\"\n}");
}
use of com.google.gson.GsonBuilder in project immutables by immutables.
the class Ent method main.
public static void main(String... args) throws UnknownHostException {
MongoClient client = new MongoClient("localhost");
RepositorySetup setup = RepositorySetup.builder().database(client.getDB("test")).executor(MoreExecutors.listeningDecorator(Executors.newCachedThreadPool())).gson(new GsonBuilder().registerTypeAdapterFactory(new GsonAdaptersEnt()).create()).build();
EntRepository repository = new EntRepository(setup);
EntRepository.Criteria where = repository.criteria().uuid("8b7a881c-6ccb-4ada-8f6a-60cc99e6aa20").actionIn("BAN", "IPBAN");
Criteria or = where.expiresAbsent().or().with(where).expiresGreaterThan(TimeInstant.of(1467364749679L));
System.out.println(or);
repository.find(or).fetchAll().getUnchecked();
}
use of com.google.gson.GsonBuilder in project scss-lint-plugin by idok.
the class Lint method parse.
// public File file;
//
// public static Lint read(String xml) {
// XStream xstream = new XStream();
// xstream.alias("lint", Lint.class);
// xstream.alias("file", File.class);
// xstream.alias("issue", Issue.class);
// xstream.addImplicitCollection(File.class, "issues");
// xstream.useAttributeFor(File.class, "name");
// xstream.useAttributeFor(Issue.class, "linter");
// xstream.useAttributeFor(Issue.class, "line");
// xstream.useAttributeFor(Issue.class, "column");
// xstream.useAttributeFor(Issue.class, "length");
// xstream.useAttributeFor(Issue.class, "severity");
// xstream.useAttributeFor(Issue.class, "reason");
// return (Lint) xstream.fromXML(xml);
// }
//
// public static class File {
// public String name;
// public List<Issue> issues = new ArrayList<Issue>();
// }
public static Map<String, List<Issue>> parse(String json) {
GsonBuilder builder = new GsonBuilder();
// builder.registerTypeAdapterFactory(adapter);
Gson g = builder.setPrettyPrinting().create();
Type listType = new TypeToken<Map<String, List<Issue>>>() {
}.getType();
return g.fromJson(json, listType);
}
use of com.google.gson.GsonBuilder in project MinecraftForge by MinecraftForge.
the class MetadataCollection method from.
public static MetadataCollection from(@Nullable InputStream inputStream, String sourceName) {
if (inputStream == null) {
return new MetadataCollection();
}
InputStreamReader reader = new InputStreamReader(inputStream);
try {
MetadataCollection collection;
Gson gson = new GsonBuilder().registerTypeAdapter(ArtifactVersion.class, new ArtifactVersionAdapter()).create();
JsonParser parser = new JsonParser();
JsonElement rootElement = parser.parse(reader);
if (rootElement.isJsonArray()) {
collection = new MetadataCollection();
JsonArray jsonList = rootElement.getAsJsonArray();
collection.modList = new ModMetadata[jsonList.size()];
int i = 0;
for (JsonElement mod : jsonList) {
collection.modList[i++] = gson.fromJson(mod, ModMetadata.class);
}
} else {
collection = gson.fromJson(rootElement, MetadataCollection.class);
}
collection.parseModMetadataList();
return collection;
} catch (JsonParseException e) {
FMLLog.log(Level.ERROR, e, "The mcmod.info file in %s cannot be parsed as valid JSON. It will be ignored", sourceName);
return new MetadataCollection();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
Aggregations