List of usage examples for com.google.gson GsonBuilder setPrettyPrinting
public GsonBuilder setPrettyPrinting()
From source file:org.eclipse.che.api.local.storage.LocalStorage.java
License:Open Source License
public LocalStorage(String rootDirPath, String fileName, Map<Class<?>, Object> typeAdapters) throws IOException { File rootDir = new File(rootDirPath); if (!rootDir.exists() && !rootDir.mkdirs()) { throw new IOException("Impossible to create root folder for local storage"); }//from ww w .j av a2s. co m storedFile = new File(rootDir, fileName); GsonBuilder builder = new GsonBuilder(); for (Map.Entry<Class<?>, Object> adapter : typeAdapters.entrySet()) { builder.registerTypeAdapter(adapter.getKey(), adapter.getValue()); } gson = builder.setPrettyPrinting().create(); }
From source file:org.eclipse.che.api.workspace.server.stack.StackTypeAdaptersProvider.java
License:Open Source License
@Inject public StackTypeAdaptersProvider() { adapters = new HashMap<>(); adapters.put(StackComponent.class, new StackComponentAdapter()); adapters.put(WorkspaceConfig.class, new WorkspaceConfigAdapter()); adapters.put(ProjectConfig.class, new ProjectConfigAdapter()); adapters.put(Environment.class, new EnvironmentAdapter()); adapters.put(Command.class, new CommandAdapter()); adapters.put(Recipe.class, new RecipeTypeAdapter()); adapters.put(Limits.class, new LimitsAdapter()); adapters.put(MachineSource.class, new MachineSourceAdapter()); adapters.put(MachineConfig.class, new MachineSourceAdapter()); adapters.put(StackSource.class, new StackSourceAdapter()); adapters.put(Permissions.class, new PermissionsAdapter()); adapters.put(Group.class, new GroupAdapter()); adapters.put(StackIcon.class, new StackIconAdapter()); GsonBuilder gsonBuilder = new GsonBuilder(); for (Map.Entry<Class<?>, Object> adapter : adapters.entrySet()) { gsonBuilder.registerTypeAdapter(adapter.getKey(), adapter.getValue()); }/*from w w w . j a v a 2s . c om*/ gson = gsonBuilder.setPrettyPrinting().create(); }
From source file:org.eclipse.epp.internal.logging.aeri.ui.model.Reports.java
License:Open Source License
private static Gson createGson(boolean pretty) { GsonBuilder builder = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); builder.registerTypeAdapter(UUID.class, new UuidTypeAdapter()); builder.addSerializationExclusionStrategy(new EmfFieldExclusionStrategy()); if (pretty) { builder.setPrettyPrinting(); }/*from w w w . j a v a 2 s .c o m*/ Gson gson = builder.create(); return gson; }
From source file:org.eclipse.epp.internal.logging.aeri.ui.utils.Json.java
License:Open Source License
static synchronized Gson getInstance() { if (gson == null) { final GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(UUID.class, new UuidTypeAdapter()); builder.enableComplexMapKeySerialization(); builder.setPrettyPrinting(); gson = builder.create();/* w w w. j a v a 2s. c om*/ } return gson; }
From source file:org.eclipse.leshan.core.model.Ddf2JsonGenerator.java
License:Open Source License
public Ddf2JsonGenerator() { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ObjectModel.class, new ObjectModelSerializer()); gsonBuilder.registerTypeAdapter(ResourceModel.class, new ResourceModelSerializer()); gsonBuilder.setPrettyPrinting(); gson = gsonBuilder.create();/* ww w. j a v a2 s .co m*/ }
From source file:org.eclipse.leshan.core.objectspec.Ddf2JsonGenerator.java
License:Open Source License
public Ddf2JsonGenerator() { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ObjectSpec.class, new ObjectSpecSerializer()); gsonBuilder.registerTypeAdapter(ResourceSpec.class, new ResourceSpecSerializer()); gsonBuilder.setPrettyPrinting(); gson = gsonBuilder.create();/*from w w w. ja v a 2s . c o m*/ }
From source file:org.eclipse.leshan.server.bootstrap.demo.BootstrapStoreImpl.java
License:Open Source License
/** * @param filename the file path to persist the registry *///from w w w . jav a 2 s .com public BootstrapStoreImpl(String filename) { Validate.notEmpty(filename); GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); this.gson = builder.create(); this.gsonType = new TypeToken<Map<String, BootstrapConfig>>() { }.getType(); this.filename = filename; this.loadFromFile(); }
From source file:org.eclipse.leshan.server.bootstrap.demo.JSONFileBootstrapStore.java
License:Open Source License
/** * @param filename the file path to persist the registry */// ww w. j a va 2s.c o m public JSONFileBootstrapStore(String filename) { Validate.notEmpty(filename); GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); this.gson = builder.create(); this.gsonType = new TypeToken<Map<String, BootstrapConfig>>() { }.getType(); this.filename = filename; this.loadFromFile(); }
From source file:org.eclipse.packagedrone.repo.adapter.npm.ModuleHandler.java
License:Open Source License
public void process(final OutputStream stream) throws IOException { final String sitePrefix = this.service.getDefaultSitePrefix(); final GsonBuilder builder = new GsonBuilder(); if (this.pretty) { builder.setPrettyPrinting(); }/*from w w w. j a v a 2 s .c o m*/ builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); final Gson gson = builder.create(); final JsonParser parser = new JsonParser(); final TreeMap<String, PackageEntry> versions = new TreeMap<>(); for (final ArtifactInformation art : this.channel.getArtifacts()) { final String pkg = art.getMetaData().get(KEY_NPM_PACKAGE_JSON); if (pkg == null) { continue; } try { final JsonElement pkgEle = parser.parse(pkg); final PackageInfo pi = gson.fromJson(pkgEle, PackageInfo.class); if (!this.moduleName.equals(pi.getName())) { continue; } versions.put(pi.getVersion(), new PackageEntry(pi, pkgEle, art)); } catch (final Exception e) { logger.info("Failed to parse package.json of " + art.getId(), e); continue; } } // now build the main file final JsonObject main = new JsonObject(); // pull in meta data from most recent version main.addProperty("name", this.moduleName); if (!versions.isEmpty()) { final Entry<String, PackageEntry> mostRecent = versions.lastEntry(); final PackageInfo pi = mostRecent.getValue().getInfo(); main.addProperty("license", pi.getLicense()); final JsonObject distTags = new JsonObject(); main.add("dist-tags", distTags); distTags.addProperty("latest", pi.getVersion()); } final JsonObject times = new JsonObject(); main.add("time", times); final JsonObject versionsEle = new JsonObject(); main.add("versions", versionsEle); for (final Map.Entry<String, PackageEntry> entry : versions.entrySet()) { final PackageInfo pi = entry.getValue().getInfo(); final ArtifactInformation art = entry.getValue().getArtifact(); times.add(pi.getVersion(), gson.toJsonTree(art.getCreationTimestamp())); final JsonObject ele = (JsonObject) entry.getValue().getElement(); final JsonObject dist = new JsonObject(); dist.addProperty("shasum", art.getMetaData().get(KEY_SHA1)); dist.addProperty("tarball", String.format("%s/artifact/%s/dump", sitePrefix, art.getId())); ele.add("dist", dist); versionsEle.add(pi.getVersion(), ele); } // render try (OutputStreamWriter out = new OutputStreamWriter(stream, StandardCharsets.UTF_8)) { gson.toJson(main, out); } }
From source file:org.eclipse.packagedrone.repo.channel.apm.ChannelModelProvider.java
License:Open Source License
static Gson createGson() { final GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); builder.setLongSerializationPolicy(LongSerializationPolicy.STRING); builder.setDateFormat(DATE_FORMAT);//from w ww. j a v a2 s.c o m builder.registerTypeAdapter(MetaKey.class, new JsonDeserializer<MetaKey>() { @Override public MetaKey deserialize(final JsonElement json, final Type type, final JsonDeserializationContext ctx) throws JsonParseException { return MetaKey.fromString(json.getAsString()); } }); return builder.create(); }